Skip to main content
bobsmo
Known Participant
June 7, 2019
Answered

add a random number to movieClip instance name

  • June 7, 2019
  • 1 reply
  • 346 views

I have several moviclips on stage named.  "moviClip1"  "moviClip2"  "moviClip3"

I'm generating a random number to choose a specific moviclip and  change their x,y

how do I call them ?

moviClip+[randomNumber].x =  ...

This topic has been closed for replies.
Correct answer Robert Mc Dowell

sure but you don't need to call the movieclip inside the row.

var arr:Array = [mc1,mc2,mc3,mc4]; // => this are real movieClips ,not strings (however you can also use strings and call them with this["mcxx"].

so to call the mc just do

arr[0].x = xx;

arr[1].y = xx;

now if you use strings in your array:

this[arr[0]].x = xx;

etc...

1 reply

Robert Mc Dowell
Legend
June 7, 2019

you shoud not use only numbers to name a mc.

so let's say:

var name1:String = "mc1";

to call it (if you are on the timeline)

this[name1].x = 120;

bobsmo
bobsmoAuthor
Known Participant
June 7, 2019

can I use an array ?

function setPage1(): void {

    var pageArray: Array = new Array();

    pageArray[1] = _myContent.page1;

    pageArray[2] = _myContent.page2;

    pageArray[3] = _myContent.page3;

    pageArray[randPage1].x = _myContent.place1.x;

    pageArray[randPage1].y = _myContent.place1.y;

}

Robert Mc Dowell
Robert Mc DowellCorrect answer
Legend
June 7, 2019

sure but you don't need to call the movieclip inside the row.

var arr:Array = [mc1,mc2,mc3,mc4]; // => this are real movieClips ,not strings (however you can also use strings and call them with this["mcxx"].

so to call the mc just do

arr[0].x = xx;

arr[1].y = xx;

now if you use strings in your array:

this[arr[0]].x = xx;

etc...