Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : Declaring MovieClipLoader Objects in loop


Point Happy
3/30/2007 7:44:49 PM
I'm trying to clean up my code. I have a varying number of MovieClipLoaders
and related listeners.

I wanted to make a general purpose loop to create them where I can call the
function with a variable and instantiate both the MovieClipLoader and its
listener.

I'm starting with pretty typical MovieClipLoader code.

var MCname = new MovieClipLoader();
var MCListener = MCSlotname+"Listener";
var MCListener:Object = new Object();
MCSlotname.addListener(MCListener);
//Load Files
MCListener.onLoadComplete = function(MCSlotname:MovieClip) {
_global.MCname.Loaded = true;
};

But if I try to put it into a function and pass a variable so that each call
to the function will instantiate a different movieclip loader it seems I run
into a problem.

function MakeLoader(InstanceName){
var MCname = new MovieClipLoader();
}

How do I use the value of the instanceName to provide a unique var name for
the instancing of the new MovieClipLoader?

Thanks.
abeall
3/30/2007 9:46:27 PM
[quoted text, click to view]

That won't do what I imagine you want it to do. The first line gets
overwritten by the second line.

[quoted text, click to view]

There are a couple of different ways this could be approached. The most
literal answer to your question I think would be:

this['loader_'+instanceName] = new MovieClipLoader();

So, say the instance name is "myClipOne", it would make:
this.listener_myClipOne

However, here are a couple other things to consider:
1) A single MovieClipLoader can load multiple clips at once.
2) Neither the MovieClipLoader nor the listener need to be assigned to a
variable, or unique variable. They will function the same wether or not there
is a reference to them in variable.
AddThis Social Bookmark Button