Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I apply a function to each movie clip in an array?
    text
    copied!<p>At the beginning my stage is empty, I've an empty array and some global variables, and I have two movie clips in my library: one is a trigger, second is the movie clip that is placed on the stage when the trigger is activated (a testdummy, if you want).</p> <pre><code>var dummies:Array = []; var i:int = 300; var j:int = 500; var k:int = 0; </code></pre> <p>Then I place an instance of the trigger on the stage</p> <pre><code>var testaddbutton:AdditionButton = new AdditionButton(); addChild(testaddbutton); testaddbutton.x = i; testaddbutton.y = i; </code></pre> <p>Then I describe the behavior of the trigger movie clip. When it is clicked, a new instance of dummy clip is placed on stage, is inserted into array, and finally certain dynamic text fields within the created instance are assigned certain values (not the point really)</p> <pre><code>testaddbutton.addEventListener(MouseEvent.CLICK, placedummy); function placedummy(evt:MouseEvent):void { var dummy:Dummy = new Dummy(); addChild(dummy); dummies.push(dummy); dummies[k].x=i + l*100; dummies[k].y=j; k++; dummy.dummyindex.text = k.toString(); } </code></pre> <p>But then I face a problem. I want the dummies to execute a function when they are clicked. When I try to add an eventListener to dummy...</p> <pre><code>//dummy.addEventListener(MouseEvent.CLICK, showlifesigns); //function showlifesigns(evt:MouseEvent):void { // trace ("pew"); //} </code></pre> <p>...I get an obvious error : Scene 1, Layer 'actions', Frame 1, Line 66 1120: Access of undefined property dummy. Because dummies are created within a function. I don't have any trouble addressing items in the 'dummies' array though.</p> <p>Though dummies are crated by the same pattern, data stored in them is the whole point of creating the application.</p> <p>So the question is: how can I apply a function to each of those dummies, which is executed on click and affects only one dummy?</p> <p>Thanks in advance</p>
 

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