Skip to main content
Participating Frequently
June 13, 2009
Answered

Accessing a movieclip instance created with AS.

  • June 13, 2009
  • 1 reply
  • 698 views

If I attach a new movie clip and give it a name by concatenating the instance name with a variable number (such as "myMovie + myVar" so that I get "myMovie1", "myMovie2", etc.), how do I then access the resulting instance in order to assign properties? MyMovie + myVar._x = 500 not surprisingly doesn't work. I presume I need to assign the value to a string variable, and then somehow assign that variable as the instance name of the movieclip?

Thanks.

This topic has been closed for replies.
Correct answer kglad

that's incorrect syntax and contains a typo.  try:


var myVar:Number = 1;

this.attachMovie("Square_mc","Square_mc"+myVar,this.getNextHighestDepth()) ;

this["Square_mc"+myVar]._x = 300;

1 reply

kglad
Community Expert
Community Expert
June 13, 2009

use array notation:

this["myMovie" + myVar]._x = 500
MarkBorokAuthor
Participating Frequently
June 13, 2009

Thanks, but it doesn't seem to work. Here is a really simple example I tried:

var myVar:Number = 1;

this.attachMovie("Square_mc",this["Square_mc"+myVar],this.getNextHighestDepth());

this["Square_mc"+myvar]._x = 300;

This attaches the movie clip just fine, but doesn't move it to x=300.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 13, 2009

that's incorrect syntax and contains a typo.  try:


var myVar:Number = 1;

this.attachMovie("Square_mc","Square_mc"+myVar,this.getNextHighestDepth()) ;

this["Square_mc"+myVar]._x = 300;