Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Unload and Stop swf from stage

Explorer ,
Jun 07, 2012 Jun 07, 2012

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);

}

TOPICS
ActionScript
8.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 10, 2012 Jun 10, 2012

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();

    }

   

...
Translate
Community Expert ,
Jun 10, 2012 Jun 10, 2012

is "menu file" your main swf?  ie, the first one that appears when your application starts?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 10, 2012 Jun 10, 2012

Hi,

Yes my dear flash grand master.

menu.swf is the first opening file. From here user can go to all 20 categories by clicking buttons which are available on menu.swf.

From any 20 categories they can come back to menu.swf by clicking home button.

Next category should be AUTOPLAYED, if they don't click on HOME button.

Please suggest me good ActionScript tutorial also.

Awaiting your reply.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2012 Jun 11, 2012

Hi Grand Master ( kglad ),

As you had told in 23rd reply the initially loaded file can be unloaded using Actionscript I did little trick in order to get this work done. I have kept the intial swf as just a background with the same stage color of all other swfs (All swfs are going to have same stage color) without anything controls in it. I just added the loadF and unloadF functions in that.

I consider this as parent. I load menu.swf from this using loadF();

From menu.swf I call other categories by clicking buttons using

MovieClip(this.parent.parent).loadF("categoryabc.swf");

It seems to work right now. Let me complete this project and let you know.

I want to know one thing that would there be any memory overloading issue arise as one swf is always staying at back? But there is no controls in it. I even checked it and it doesn't exhaust machine's memory.

Thanks for your great and timely help. You really rock.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2012 Jun 11, 2012
LATEST

one swf (the main one or menu.swf in your situation) always remains loaded.  you can stop all sounds in it (SoundMixer.stopAll() ) and you can position a stage colored and sized rectangle over everything in your main swf so it "appears" to be unloaded but you can't unload it.

and no, one swf will not overload memory unless it is creating more and more objects.  you can use System.totalMemory in an enterframe loops (for example) to check whether you have a memory leak.

p.s.  please mark helpful/correct responses, if there are any.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines