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

Load and Unload multiple SWFs

Community Beginner ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

Hello everyone...

This is my biggest problem in Animate AS3 ever. So the problem is-

I have 8 SWFs which have separate topic in each and one main SWF file and i want to connect all of them together like-

Firstly i open Main SWF then it shows all the 8 topics name with each button. i used script from code snippets which is 'Click to load/unload SWF' and i assigned all the SWF as it required to open. I have created a button in each SWF to go back to main SWF using same code as i mentioned.... It is working properly but i realized that each time i click to open new SWF, it overlape on old one and when i open multiple times all SWFs, it become very heavy and get legging and hangs very much, consumes more memory...

So what can i do to load new SWF and unload all previous SWFs by clicking on same button in each SWF ???????

Please give some idea with whole script which i have to paste with button name and file name(u can assume any button name and file name).

As i don't have enough knowledge about writing manual code.

Please give some positive response.

Thanks....

TOPICS
ActionScript

Views

938

Translate

Translate

Report

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 ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

use one loader for all your loads (eg, loader) and use:

if(loader.content){

loader.unloadAndStop();

}

loader.load(new URLRequest(whatever));

Votes

Translate

Translate

Report

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 Beginner ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

Sir,

Thanks for your reply... But can you please give detailed script for just one file ???

Votes

Translate

Translate

Report

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 Beginner ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

I mean, full script... Not just a part....

Votes

Translate

Translate

Report

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 ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

remove the code in your loaded swfs that unloads them.

in your main swf youl would use something like:

var loader:Loader=new Loader();

addChild(loader);

// if you're using movieclip buttons topic_0, topic_1 etc to load swfs topic_0.swf, topic_1.swf etc

for(var i:int=0;i<8;i++){

this['topic_'+i].ivar=i;

this['topic_'+i].addEventListener(MouseEvent.CLICK,loadF);

}

function loadF(e:MouseEvent):void{

if(loader.content){

loader.unloadAndStop();

}

loader.load(new URLRequest('topic_'+MovieClip(e.currentTarget).ivar+'.swf'));

}

Votes

Translate

Translate

Report

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 Beginner ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

These are the actual files which you can see how is it working...

So when i open again and again these files it gets heavier and lags...

please describe code....

Votes

Translate

Translate

Report

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 ,
Apr 09, 2018 Apr 09, 2018

Copy link to clipboard

Copied

use the code i suggested.  change button names and swf names to match the code, or change the code to match your button and swf names.

Votes

Translate

Translate

Report

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 Beginner ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

i pasted the code but nothing happen... Please describe me where i have to paste button name and SWF's name?

Screenshot (1).png

Votes

Translate

Translate

Report

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 ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

:

var loader:Loader=new Loader();

addChild(loader);

// if you're using movieclip buttons topic_0, topic_1 etc to load swfs topic_0.swf, topic_1.swf etc

for(var i:int=0;i<8;i++){

this['topic_'+i].ivar=i;  // this['topic_'+i] are your button names

this['topic_'+i].addEventListener(MouseEvent.CLICK,loadF);

}

function loadF(e:MouseEvent):void{

if(loader.content){

loader.unloadAndStop();

}

loader.load(new URLRequest('Smart Achivement'+MovieClip(e.currentTarget).ivar+'.swf'));

}

Votes

Translate

Translate

Report

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 Beginner ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

Screenshot (2).png

It's showing this error....

TypeError: Error #1010: A term is undefined and has no properties.

at SmartAchivment_fla::MainTimeline/frame1()

I pasted this code-

var loader:Loader=new Loader();

addChild(loader);

// if you're using movieclip buttons topic_0, topic_1 etc to load swfs topic_0.swf, topic_1.swf etc

for(var i:int=0;i<8;i++){

this['button_2'+i].ivar=i;  // this['topic_'+i] are your button names (Button Name which i have to press to go to other SWF =button_2

this['button_2'+i].addEventListener(MouseEvent.CLICK,loadF);

}

function loadF(e:MouseEvent):void{

if(loader.content){

loader.unloadAndStop();

}

loader.load(new URLRequest('Index'+MovieClip(e.currentTarget).ivar+'.swf'));     (SWF name which is Main SWF, i have to load = Index.swf)

}

Votes

Translate

Translate

Report

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 ,
Apr 10, 2018 Apr 10, 2018

Copy link to clipboard

Copied

your button names are incorrect.

do you have movieclips named button_0, button_1 etc?

Votes

Translate

Translate

Report

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 Beginner ,
Apr 11, 2018 Apr 11, 2018

Copy link to clipboard

Copied

Final.jpg

Votes

Translate

Translate

Report

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 ,
Apr 11, 2018 Apr 11, 2018

Copy link to clipboard

Copied

and what's ButtonHome supposed to do?

Votes

Translate

Translate

Report

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
Advisor ,
Apr 11, 2018 Apr 11, 2018

Copy link to clipboard

Copied

a little suggestion, GreenSock is a wonderful library to load multiple swf with maximum of optimization

Votes

Translate

Translate

Report

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 Beginner ,
Apr 11, 2018 Apr 11, 2018

Copy link to clipboard

Copied

'ButtonHome' will load main SWF.

Votes

Translate

Translate

Report

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 ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

LATEST

again, remove the code in your loaded swfs that unloads them.

Votes

Translate

Translate

Report

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