Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can we control behavior of individual movie clips added randomly to stage from an array [as3]
    primarykey
    data
    text
    <p>The code below adds a movie clip to the stage randomly from an array of movie clips. Once a movie clip is added to stage it moves horizontally on an x axis by echoing a corresponding sound clip. But my problem is, only the same sound clip is being played for any of the movie clips added on stage. The reason why its happening is of course because of the line: </p> <pre><code>var mc:MovieClip = new enemies[printArray[p]]; </code></pre> <p>Can anyone please tell me how i can individually control the behavior of each movie clip that falls within "var mc". Instead of writing something like:</p> <pre><code>if(mc.x &lt;= -100) { Enem1Timer.stop()} else if(mc.x &lt;= 570){ Enem1Timer.start() } </code></pre> <p>is there a way to write like: </p> <pre><code>if(Enem1.x &lt;= -100)..... </code></pre> <p>Any help is most welcome. Thanx in advance.</p> <pre><code>import flash.utils.Timer; import flash.display.MovieClip; var sound1:Letter1 = new Letter1(); var sound2:Letter2 = new Letter2(); var sound3:Letter3 = new Letter3(); var sound4:Letter4 = new Letter4(); var sound5:Letter5 = new Letter5(); var sound6:Letter6 = new Letter6(); var printArray:Array = [0, 1, 2, 3, 4, 5]; var enemies:Array = [Enem1, Enem2, Enem3, Enem4, Enem5, Enem6]; for(var n:int = 0; n &lt;= 6; n++) { var randNo:int = int(Math.random() * 6); printArray.push(randNo); } var Enem1Timer:Timer = new Timer(1000, 1); Enem1Timer.addEventListener(TimerEvent.TIMER, playA1); function playA1(e:TimerEvent):void {sound1.play();} for(var p:int = 0; p &lt; printArray.length; p++) { trace(printArray[p]); var mc:MovieClip = new enemies[printArray[p]]; addChild(mc); mc.x = 600; mc.y = 200; stage.addEventListener(Event.ENTER_FRAME, loop) function loop(e:Event){ if(mc.x &lt;= -100) { Enem1Timer.stop()} else if(mc.x &lt;= 570){ Enem1Timer.start() } mc.x -= 3; }} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload