Skip to main content
Known Participant
September 29, 2006
Answered

Dynamically creating a movieclip name

  • September 29, 2006
  • 2 replies
  • 273 views
I have a series of tiny movieclips (about 100 of them, cannot be created at runtime) already exisit in my main movie.
These have been name from A1 to A100. I have to refer to one of these movieclips depending on a value calculated at runtime from 1 to 100. I don't want to use a switch & case statment, because there would be too many of them.
How can I create a movieclip variable in AS and assign one of the existing movieclips as the actual object?
For example I tried:
var MCobj:MovieClip = "A" + calculatedNumber;
But this does not create a valid reference to the existing MC. Any ideas?
Thanks
This topic has been closed for replies.
Correct answer kglad
use array notation to help flash resolve your string into a movieclip:

2 replies

kglad
Community Expert
Community Expert
September 29, 2006
use the trace() function to see if calculatedNumber gives the result you expect and make sure your movieclips (A1 etc) are on the _root timeline.
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 29, 2006
use array notation to help flash resolve your string into a movieclip:

Known Participant
September 29, 2006
Thanks for the kglad. This does create a movie clip, but this isn't pointing to the existing mc. I'm not able to script the movie clip object and control the one thal already exisits. I even tried the eval, but don't know why this is not working.