PDA

View Full Version : using for statement to attachMovie Clips...


montana_13
03-13-2006, 05:03 PM
Hi guys... I'm a new member and also new to actionscript... my question is:

I have this code:

function addClips(sLinkage:String, sLinkage2:String, sLinkage3:String, sLinkage4:String, sLinkage5:String, sLinkage6:String, sLinkage7:String):Void {
var mcImage:MovieClip = attachMovie(sLinkage, "mcImage", this.getNextHighestDepth(), {_x:600, _y:395, _xscale:20, _yscale:20});
var mcText:MovieClip = attachMovie(sLinkage2, "mcText", this.getNextHighestDepth(), {_x:400, _y:500});
var image002:MovieClip = attachMovie(sLinkage3, "image002", this.getNextHighestDepth, {_x:600, _y:395, _xscale:20, _yscale:20});

}

i m calling the function through an event handler... and my code is working just fine.... but what i want to know is how can i use the for statement instead of making a new variable for each movie clip i attach??

thanks

Xeef
03-13-2006, 06:52 PM
i don't see any continuiti here !

sLinkage coud by used in a loop but woudn't bring to much in the meaning of saving writeing work

each instant name is unique same the "var" name
the _x _y are also variing
there isn't on all a _xscal/_yscale


this is just an exmple !


function addClips(Clips) {
for (a=0; a<Clips.length; a++) {
Clips[a].X = (Clips[a].X != undefined) ? Clips[a].X : 600;
Clips[a].Y = (Clips[a].Y != undefined) ? Clips[a].Y : 395;
Clips[a].XS = (Clips[a].XS != undefined) ? Clips[a].XS : 100;
Clips[a].YS = (Clips[a].YS != undefined) ? Clips[a].YS : 100;
trace("var "+Clips[a].Name+":MovieClip = attachMovie("+Clips[a].Linkage+' "'+Clips[a].Name+'", '+'{_x:'+Clips[a].X+", _y:"+Clips[a].Y+", _xscale:"+Clips[a].XS+", _yscale:"+Clips[a].YS+"})");
}
}
CLIPS = new Array();
CLIPS[0] = {Name:"sLinkage", Linkage:"sLinkage",XS:20,YS:20};
CLIPS[1] = {Name:"mcText", Linkage:"sLinkage2", X:600, Y:395};
CLIPS[2] = {Name:"image002", Linkage:"sLinkage3",XS:20,YS:20};
addClips(CLIPS);

montana_13
03-13-2006, 08:02 PM
thanks....

i'll try to do it using your example and i'll let u know if it's working...