2013-02-01 2 views
0

Flash CS5를 사용하여 ActionScript 3.0을 사용하여 외부 SWF를로드 및 언로드하는 ComboBox를 만들려고합니다.ComboBox AS3을 통해 외부 SWF로드

현재 콤보 상자에는 홈 및 약 2 개의 목록 항목이 있습니다. ComboBox에서 홈 또는 정보 옵션을 선택하면 선택한 경우 즉시 홈 및 About SWF가 모두 표시됩니다.

오직 하나의 SWF가 선택되었을 때만 표시됩니다. 전체가 아닌.

menuList.addItem({label:"Choose"}); 
menuList.addItem({label:"Home",path:"home_load.swf"}); 
menuList.addItem({label:"About",path:"about.swf"}); 

menuList.addEventListener(Event.CHANGE, Home); 
menuList.addEventListener(Event.CHANGE, About); 

var loader:Loader = new Loader(); 
loader.unloadAndStop(); 


function Home(e:Event):void 
{ 
    if (e.currentTarget.selectedItem.path) 
    { 
     var loader:Loader = new Loader(); 
     //loader.unloadAndStop(); 
     loader.load(new URLRequest("home_load.swf")); 

     addChild(loader); 
     //loader.unloadAndStop(); 
     loader.x = 0; 
     loader.y = 190; 
    } 
} 

function About(e:Event):void 
{ 
    if (e.currentTarget.selectedItem.path) 
    { 
     //loader.unloadAndStop(); 
     var loader:Loader = new Loader(); 
     loader.load(new URLRequest("about.swf")); 

     addChild(loader); 
     //loader.unloadAndStop(); 
     loader.x = 0; 
     loader.y = 190; 
    } 
} 

답변

0

swf 파일로드가 완료되면 addChild를 수행해야 할 수도 있습니다.

//These listeners detect when the file has finished loading, and if the 
//correct file is loaded. 
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading); 
swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 

//The load method then loads the SWF file into the loader object. 
swfLoader.load(my_url); 

//This function adds the external SWF to the stage. 
function finishLoading(loadEvent:Event) { 
addChild(loadEvent.currentTarget.content); 
} 

//This function displays a message if the file is not found. 
function errorHandler(errorEvent:Event):void { 
trace("file missing"); 
} 
+0

이제로드되지만 ComboBox의 옵션 중 하나를 클릭하면 외부 SWF가 모두로드됩니다. SWF를 한 번 언로드하고로드해야합니다. 위 코드를 업데이트했습니다. – user2031159

+0

@ user2031159 change 이벤트에 2 개의 이벤트 리스너를 추가하고 각 이벤트 핸들러가 SWF를로드하기 때문에 두 SWF를 모두로드합니다. 이벤트 리스너를 하나만 추가하고 이벤트를 처리하는 함수에서 선택한 항목의 콤보 상자를 쿼리하고로드 할 swf를 결정하십시오. –

관련 문제