Skip to main content
Inspiring
April 1, 2009
Answered

Use string variable in Movie functions

  • April 1, 2009
  • 2 replies
  • 426 views
I want to know how to use a string variable as the URL in a Movie Clip event.

sample code:
var numCount:Number = 1;
var strMov:String = "rock" + numCount;
bob.removeMovieClip(strMov);

Thanks so much!
This topic has been closed for replies.
Correct answer darmahart
It turns out, I solved my own issue. I feel a bit foolish. Thanks for your help!

2 replies

Ned Murphy
Legend
April 1, 2009
removeMovieClip has often been a challenge for me to try to implement by trying to comprehend it. I usually just attack it until I get the results... so try a couple or more until it works...

bob[strMov].removeMovieClip();

removeMovieClip(bob[strMov] );

The most important aspect of using removeMovieClip is that it can only remove objects that were added dynamically.
darmahartAuthor
Inspiring
April 1, 2009
Thanks. The movie was added dynamically. My next question is how to use that with attachMovie. What I have now is:

bob.attachMovie("rock2","r2",this.getNextHighestDepth());

What is want is a way to substitute a string I can use with a counter variable for "rock2" such as "rock" + counter.

Thanks!
darmahartAuthorCorrect answer
Inspiring
April 1, 2009
It turns out, I solved my own issue. I feel a bit foolish. Thanks for your help!
Ned Murphy
Legend
April 1, 2009
To use a string to target an object, use the bracket/array notation...

bob["rock"+numCount]

OR

bob[strMov]
darmahartAuthor
Inspiring
April 1, 2009
Thanks for you answer. My next question is how do I combine that with bob.removeMovieClip()?

I have rarely used ActionScript and was asked for help from a friend. I'm learning on the fly.