320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Having a weird issues… totaly new to AS3 . I’m loading multiple external swfs. No big deal…

I have two movie clips. One movie clip with 10 thumbnails and the other movie clip loading the external swfs. I want the external swfs to be loaded as I click on any thumbnail.

I’m trying to have the two movieclips talk to each other and I got it…. kinda. At least the trace statement is working…. how do I get it to swap out the swfs from another movieclip?

Here is all my code:

Thumbnails (thumbnails_mc)
var backGrounds:backgrounds = new backgrounds();
bg1_btn.addEventListener(MouseEvent.CLICK, backGrounds.clickHandler);
bg2_btn.addEventListener(MouseEvent.CLICK, backGrounds.clickHandler);
Code for external swfs. (background_mc)
var container:Sprite = new Sprite();
addChild(container);

function clickHandler(e:Event):void{

 while(container.numChildren == 1) container.removeChildAt(0);

 switch(e.target.name){
  case "bg1_btn": loadSwf("background1.swf"); break;
  case "bg2_btn": loadSwf("background2.swf"); break;
 } 

 trace("background changed?");
}

function loadSwf(swfName:String):void{
 var loader:Loader = new Loader(); 
 loader.load(new URLRequest(swfName));
 container.addChild(loader);
}
812 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee says

Don’t have my flash loaded at the moment…

But on the function ‘click handler’ seems a little convoluted for doing something a simple as loading a different movie swf on a button click.

Let me see.

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

awesome! thanks :)

812 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
iamthwee says

Ok it might be tomorrow though as it’s night time here.

1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

Try reusing the loader instead of creating the new one each time. Also add at least some event listeners for the loader like error caching and complete.

4140 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Located in Brazil
+3 more
tsafi says

Some crap flash philosophy for you .

When you come from the As2 world in to AS3 world first thing you do is try to think like AS2 dev and assign it as AS3 , sure you can go around it for some time but at the end you going to hit the break wall, the communication between external swf and between external Mc is the number 1 issue many struggle on the long way.

I can say most of us exploit this issue via the class and we love to reuse stuff in a very easy matter, but its really not one of those topics we can throw a straight easy answer

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

@Tean – Thanks. I’ll mess with that idea.

@tsafi – Gotcha. Yeah i’m seeing those brick walls lol

Thanks guys.

1234 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
+5 more
MBMedia says
while(container.numChildren == 1) container.removeChildAt(0);

Only removes children if there’s exactly 1. Have 2 and it’ll do nothing, won’t even remove 1 of them. Try this:

while(container.numChildren > 0) container.removeChildAt(0);

That’ll remove all children of the container.

4140 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Located in Brazil
+3 more
tsafi says

That’ll remove all children of the container.
Not always; you know if you extended your children for example under a loop via let’s say extend class i notice the extend object is not been kick out from the GC right away so even so…. i will go in to the extended sometime and remove the actual children set them to null before i will remove the container it’s like a double check, but i know my GC will kick in right away, so when you have lots of particles you will notice it right away on the free mem`
320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

while(container.numChildren == 1) container.removeChildAt(0);

Didn’t work. It works great if I bring those thumbnails inside the same movieclip (background_mc) but outside just doesn’t seem to trigger it.

Thanks guys Tim

by
by
by
by
by
by