Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

add a random number to movieClip instance name

New Here ,
Jun 07, 2019 Jun 07, 2019

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 =  ...

TOPICS
ActionScript
313
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Jun 07, 2019 Jun 07, 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...

Translate
Advisor ,
Jun 07, 2019 Jun 07, 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2019 Jun 07, 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 07, 2019 Jun 07, 2019
LATEST

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines