|
-
Unload not fully functioning
Hello,
I am making my website by loading each of the external pages in to the main swf file. I've used a tutorial and it manages to load all of the correct pages when the corresponding button is pressed, however I can tell that the Unload isn't working because each page has audio and I can hear them playing over the top of each other when I navigate through the pages.
Here's the code. Can anyone tell me why it's not properly unloading the previous page?
Code:
var Xpos:Number = 0;
var Ypos:Number = 102;
var pageSWF:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("home.swf");
loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
// Btns Universal function
function btnClick(event:MouseEvent):void {
removeChild(loader);
var newSWFRequest:URLRequest = new URLRequest(event.target.name + ".swf");
loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
}
-
I recently did a tutorial where he said the audio continues playing in Flash Cs4 and you must tell it to stop on entering each page.
sorry can't find the code off hand
-
So the external SWF file actually gets unloaded, but the audio continues to play regardless? Does anyone know if that's true? I still haven't found a solution for this problem.
-
Still no solution. Can anyone verify and explain this for me please?
-
*Bump* Sorry, still not solved it. Surely someone knows this?
-
Senior Member
It's hard to guess why this might not be unloading; there could be several reasons, including listeners being attached to elements in the loaded file which are preventing its complete removal; obviously it's got to be removed from the stage before it can be unloaded; and it's possible there's some issue with the playhead keeping the sound alive, although I haven't really heard anything about that before.
One thing you should be doing is using a LoaderContext on the loaded file that specifies its methods are loaded into a child or new applicationDomain, because the default behavior is to load child SWF methods into ApplicationDomain.currentDomain, which appends the methods to the code actually performing the load as soon as the load completes. Once those methods are attached, they are not removed or garbage collected even if you try to unload the swf. So this might help:
Code:
var Xpos:Number = 0;
var Ypos:Number = 102;
var pageSWF:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("home.swf");
var context:LoaderContext = new LoaderContext(true,new ApplicationDomain());
loader.load(defaultSWF,context);
-
Hi Josh, thanks for the detailed explanation and included code. It's not often people take the time out to be that thorough 
I've tried the code but sadly I get the same result. I also tried adding the "context" in to the btnClick function but it still doesn't work. Here's what I've got now:
Code:
var Xpos:Number = 0;
var Ypos:Number = 102;
var pageSWF:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("home.swf");
var context:LoaderContext = new LoaderContext(true,new ApplicationDomain());
loader.load(defaultSWF,context);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
// Btns Universal function
function btnClick(event:MouseEvent):void {
removeChild(loader);
var newSWFRequest:URLRequest = new URLRequest(event.target.name + ".swf");
loader.load(newSWFRequest, context);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
}
And yet the previous page doesnt unload. Hmm! Any ideas why?
-
Have you tried to stop all sounds?
AS3:
SoundMixer.stopAll();
AS2:
stopAllSounds();
Hope this what you were looking for...
-
Haha! That is absolutely genius. I guess Flash continues to play sounds, even if the movies are unloaded...? Thanks for your help mykhel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|