Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
ArdentKid

Creating multiple MovieClip instances from loading a SWF

Recommended Posts

I'm using LoaderMax, and can't seem to figure out how to create a new instance of a movieclip it loads. I am loading an external SWF with a mc in the library. I'm new-ish to as3 so please be gentle.

 

I think without LoaderMax, I would want to load the swf, and then do something like:

 

var ObjectdAsset:Class = applicationDomain.getDefinition('mc_name');

var instance1 = new ObjectAsset();

var instance2 = new ObjectAsset();

...etc

 

Much appreciated :)

Link to post
Share on other sites

Hi, and welcome to the forums.

 

Yes, you can use SWFLoader's getClass() method to do exactly what you want.

 

import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

var assetsSWF:SWFLoader = new SWFLoader("externalAssets.swf", {onComplete:completeHandler});

function completeHandler(e:LoaderEvent):void{
trace("loading complete");

//ceate a reference to the Circle Class in the external swf

var circle:Class = e.target.getClass("Circle");
trace(circle);

//create an instance of the Circle class and add to stage
var myNewCircle:MovieClip = new circle();
addChild(myNewCircle)
}


assetsSWF.load(); 

 

externalAssets.swf has a symbol in the Library with class of "Circle".

I have uploaded a zip containing CS4 fla files.

useAssetsFromExternalSwfLibrary.zip

Link to post
Share on other sites

Thanks, that's exactly what I needed!

 

Now I'm looking into manipulating the asset... Say I have a character_head_mc and I want to add to all instances a child accessory_hat. Do I need to keep track and iterate over all references of the head or can I somehow tell the class to now make the hat it's child?

 

In flash I could do this by dragging a hat movieclip from the library into the head movieclip.

Link to post
Share on other sites

I'm pretty sure you are going to have to iterate through all the instances of your heads and add the hats.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×