320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • 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
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
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
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

awesome! thanks :)

812 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
iamthwee says

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

1676 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 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
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
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
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • 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
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
  • United States
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
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
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
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • 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