Posts

Showing posts with the label parent-child

AS3: Adding function to population loop

AS3: Adding function to population loop Basically I have 2 movieclip objects with some code, currently just to trace them. The blue circles when clicked will say 'Blue' and the red ones when clicked will say 'Red'. This works fine in theory until I add a population loop, which adds more of them. Then only 1 of each colour correctly works, the rest are just 'mock' circles. I wish for each circle to tell me their colour. This is my code for the .fla: import flash.events.MouseEvent; BlueBall.addEventListener(MouseEvent.CLICK, fun1) function fun1(e:MouseEvent){ trace("Blue!"); } RedBall.addEventListener(MouseEvent.CLICK, fun2) function fun2(e:MouseEvent){ trace("Red!"); } and this is the population loop in an .as file: private function PopulateCircles():void { for (var i:int=0; i < 10; i++) { var blueCircle:BlueCircle = new BlueCircle(); this.addChild(blueCircle); var redCircle:RedCircle = new RedCircle(...