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

Load and Unload multiple SWFs

Guest
Apr 09, 2018 Apr 09, 2018

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

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

if(loader.content){

loader.unloadAndStop();

}

loader.load(new URLRequest(whatever));

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

Sir,

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

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

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

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

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

}

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

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....

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

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.

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

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

Screenshot (1).png

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

:

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

}

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

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)

}

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

your button names are incorrect.

do you have movieclips named button_0, button_1 etc?

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

Final.jpg

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

and what's ButtonHome supposed to do?

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

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

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

'ButtonHome' will load main SWF.

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

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

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