Skip to main content
Inspiring
June 7, 2012
Answered

Unload and Stop swf from stage

  • June 7, 2012
  • 1 reply
  • 8031 views

Hi,

I'm a newbie to Flash and Actionscript. I need to give links to around 20 swf files via buttons from the menu.swf. I'm able to give links. But when I come back by clicking HOME button kept at the newly loaded swf the audio files are still being played at the background.

Yes, It has got audio files playing at the back for each slide in the new swfs. When Click on the same link again in menu.swf again the files are being played with the unfinished old file. It's really hectic.

I need to unload it completely from stage when I come back to menu.swf by clicking on HOME button from any of 20 categories.

I used unloadAndStop but it is not doing. I hope that I'm commiting mistakes at somewhere but couldn't predict.

Need some help !

FOR HOME BUTTON:


var _content:Loader = new Loader();

function loadContent(content:String):void {

    if (_content != null) {

        _content.unloadAndStop(true);

        removeChild(_content);

        _content = null;

    }

    var loader:Loader = new Loader();

    loader.load(new URLRequest(content)); //---->>>> I don't really know what should be put in this 😞

    _content = addChild(loader) as Loader;

}

Home_Button.addEventListener(MouseEvent.CLICK, home);

function home(event:MouseEvent) {

    _content.unloadAndStop(true);

    var homeSWF:URLRequest = new URLRequest("demo.swf");

    _content.load(homeSWF);

    addChild(_content);

}

FOR MENU.swf button

var loader:Loader = new Loader();

Category1_Button.addEventListener(MouseEvent.CLICK, category1);

function category1(event:MouseEvent):void {

    var Category1SWF:URLRequest = new URLRequest("Category1.swf");

    loader.load(Category1SWF);

    addChild(loader);

}

This topic has been closed for replies.
Correct answer kglad

Hi,

Thank you so much for spending your time with me for writing and correctind codes. But The above code doesn't work for this project.

I don't have any movie clips anywhere in this project. I have all 21 swfs ( including menu.swf ) kept in one folder in the Operating System. I didn't keep any swf inside another or pasted in Timeline. No Movie clips. I want to keep menu.swf running initially. From there we can go to all 20 categories and come back to menu.swf by clicking on home button which is available on all 20 categories.

Awaiting your workable solution. To be honest I really appreciate your help. I hope we can sort out this issue in just couple of mins, If we are in chat or something related to that.

Thanks.


i think there's a terminology issue.

your main swf is the swf that is embedded by your html page.  it is the first swf to be displayed and it cannot be unloaded using actionscript. 

it should contain loader, the only Loader instance you need.

that main swf may or may not be main.swf. 

in your main swf, you should use:

/////////////////////////////////

var loader:Loader = new Loader();

addChild(loader);

function loadF(fileS:String):void {

    if(loader.content){

        loader.unloadAndStop();

    }

    loader.load(new URLRequest(fileS));

    addChild(loader);

}

function unloadF():void{

if(loader.content){

loader.unloadAndStop();

}

}

/////////////////////////////////////////

don't change anything between the ////// lines

----------------------------------------------------

from your main swf, if you want to load "catgoryxyz.swf", use:

loadF("categoryxyz.swf");  // this argument in this line you can and will change

from you main swf, if you want to unload whatever's been loaded (and appear to return to your main swf), use:

unloadF();

---------------------------------------------------

from the main timeline of any loaded swf (like categoryxyz.swf), if you want to load "categoryabc.swf", use:

MovieClip(this.parent.parent).loadF("categoryabc.swf");  // the argument in this line you can and will change

if you want a swf to unload itself (and appear to return to your main swf), use:

MovieClip(this.parent.parent).unloadF();

-----------------------------------------------------------------

1 reply

kglad
Community Expert
June 7, 2012

there are some problems with that code.  but to start fixing that, how many different swfs do you need to load at any one time?

kumar0607Author
Inspiring
June 7, 2012

Hi kglad,

Thanks for replying in very short span of time. I'll put in this way.

Approx 20 buttons are on the stage - file named menu.swf. Each button will have link to separate swfs. Come to your valuable question. I need to load only one swf at one time.

The flow of the project is, Each swf will have around 10-12 slides with separate voice over associated with it. When one swf finishes it should automatically load the next swf.

But at any time from any swf the user should be able to come back to menu.swf by clicking on HOME button which is available on each swf.

Hope this sounds clear. Awaiting your valuable reply.

Thanks.