2013-03-02 41 views
0

我意識到這個問題之前已經被詢問過了,並且我已經嘗試了所有的大部分解決方案並且無濟於事。在我的flash文件中,我在goGallery框架中加載了一個外部.swf文件,但現在當我轉到另一個框架時,.swf文件仍處於後臺。在退出某個框架時卸載一個.swf文件

以下是代碼,如果您還可以告訴我在哪裏放置新代碼,那將會很棒,因爲我已經嘗試了多次將解決方案放入其中並在其周圍放置。

stop(); 

function listenerFunction (Event):void{ 
} 


function goHome (e:MouseEvent):void{ 
    gotoAndStop("Home"); 
} 
home_btn.addEventListener(MouseEvent.CLICK, goHome); 

function goAbout (e:MouseEvent):void{ 
    gotoAndStop("About"); 
} 
about_btn.addEventListener(MouseEvent.CLICK, goAbout); 

function goHistory (e:MouseEvent):void{ 
gotoAndStop("History"); 
} 
history_btn.addEventListener(MouseEvent.CLICK, goHistory); 

function goEducation (e:MouseEvent):void{ 
gotoAndStop("Education"); 
} 
education_btn.addEventListener(MouseEvent.CLICK, goEducation); 

function goInterests (e:MouseEvent):void{ 
gotoAndStop("Interests"); 
} 
interests_btn.addEventListener(MouseEvent.CLICK, goInterests); 

function goGoals (e:MouseEvent):void{ 
gotoAndStop("Goals"); 
} 
goals_btn.addEventListener(MouseEvent.CLICK, goGoals); 

function goPuzzle (e:MouseEvent):void{ 
gotoAndStop("Puzzle"); 
} 
puzzle_btn.addEventListener(MouseEvent.CLICK, goPuzzle); 

function goSound (e:MouseEvent):void{ 
gotoAndStop("Sound"); 
} 
sound_btn.addEventListener(MouseEvent.CLICK, goSound); 

function goGallery (e:MouseEvent):void{ 
gotoAndStop("Gallery"); 
var myLoader:Loader = new Loader();      
var url:URLRequest = new URLRequest("gallery.swf"); 
myLoader.load(url);          
addChild(myLoader); 

myLoader.x = 380;           
myLoader.y = 270; 

myLoader.scaleX = 0.45; 
myLoader.scaleY = 0.45; 

} 

gallery_btn.addEventListener(MouseEvent.CLICK, goGallery); 

回答

0

您需要保留對myLoader的引用,並在不希望出現在舞臺上時將其刪除。

var galleryLoader:Loader = new Loader(); 

function goGallery (e:MouseEvent):void{ 
    gotoAndStop("Gallery"); 

    var url:URLRequest = new URLRequest("gallery.swf"); 
    galleryLoader.load(url);          
    addChild(galleryLoader); 
} 

裏面的其他功能刪除galleryLoader:

function goHome (e:MouseEvent):void{ 
    removeGallery(); 
    gotoAndStop("Home"); 
} 

function removeGallery():void 
{ 
    if(galleryLoader.parent) 
     galleryLoader.parent.removeChild(galleryLoader); 
} 
+0

謝謝!這工作完美! – Mike 2013-03-03 15:07:06

相關問題