PDA

View Full Version : dynamically assign mc instance names?


ssipse
05-12-2004, 09:20 PM
is it possible to dynamically assign movieclip instance names?

for example, i wanna do like..

onClipEvent(){
this.instanceName = "blah"
}

vosgien
05-13-2004, 01:01 AM
Hi,
You need to create the instances dynamically, first you need a text file that should look a bit like this
&myVars=instance1,instance2,instance3,instance,.... ......and so on- you get the idea, save the file and call it myText.txt
You can create a movie clip dynamically, but for this exercise, create your clip on stage, double click it and in frame 1 put
trace(this._name)

delete it from the stage, open the library and give your clip a linkage identifier( right click - ckick on linkage), then try this code on frame 1 of the main timeline:

myLVs = new LoadVars()
myLVs.load("myText.txt")
myLVs.onLoad = function(success)
{
if(success)
{
clipWidth = 20;/*this will place the ckips 2 pixels apart*/
myInstanceNames = new Array()
myInstanceNames = this.myVars.split(",")
for(i = 0; i < myInstanceNames.length; i++)
{
attachMovie("clip",myInstanceNames[i], i,{_y:50,_x:50+clipWidth *i})
}
}
}

/*where "clip" is the linkage identifier*/


Hope that helps

Vosgien

pom
05-13-2004, 07:54 AM
Keep it simple :)this._name = "blah"