all groups > flash actionscript > june 2004 >
You're in the

flash actionscript

group:

Set Object Instance Name Via Actionscript


Set Object Instance Name Via Actionscript llama79
6/1/2004 11:14:21 PM
flash actionscript:
I know how to read what the instance name of an object is and I need to be able
to set the instance name of an object with actionscript. Here's why:

I'm creating a scrolling list of buttons that stack on top of eachother. The
number of buttons changes. One day there could be 50, another 30, etc... The
buttons are created at run time using actionscript and I need to be able to set
the button instance name at that time. I'll be doing this in a loop so the
button names will be 1,2,3,4, etc... Not that it matters, but the reason these
are done sequentially is because the instance name is used as an integer value
to be passed to a function that uses the pointer to locate correlating
information in an array.

The number of buttons will be variable and will change from day to day so this
is why I need to assign instance names on the fly.

In summary: How do you set an instance name of an object (button, movie clip)
with actionscript.


Thanks,

Joshua Lomelino
Re: Set Object Instance Name Via Actionscript mandingo
6/1/2004 11:58:01 PM
if you are creating the whole thing dynamically in a loop, then how are you
getting the button instances on the stage? if it is any sort of attachMovie or
similar, then you are required to provide a unique instance name at the
creation of these objects.

for(var x =0; x<numberOfItems; x++){
this.attachMovie("myButton","myButton"+ x,x);
}
the second parameter is the unique instance name.

if you have objects on stage and you just wish to reassign instance names in a
loop (I don't know how you are going to do that without knowing what to rename)
.... then you would need to change the ._name property of the object

for(var x=0; x<numberOfItems; x++){
this["button"+x]._name = "myButton"+x;
}

hope that helps,
cheers,
AddThis Social Bookmark Button