Here i have an actionscript3 code in which i am creating an array of objects. Basically in the array are multiple instances of the same object. I want to make an event listener which calls a function f0 which rotates the object 90 degrees. My problem is i can't find a way to asign unique identifiers to each object in array, so when i click an object i want it to rotate, but only the first element of the array rotates. I also want to center my rotation so that the object doesn't rotate in (0,0).
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.ColorTransform;
public class Main extends Sprite
{
var array = new Array();
var i:int;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
for (var i:int = 0; i < 10; i++)
{
var asd:Sprite = new Sprite();
asd.graphics.beginFill(0x0000ff);
asd.graphics.drawRect(0, 0, 60, 60);
array.push(asd);
addChild(array[i]);
array[i].x = 60 * i ;
array[i].y = 60 * i ;
array[i].addEventListener(MouseEvent.CLICK, f0);
if (i % 2 == 0) {
asd.graphics.lineTo(asd.x + 60, asd.y + 60);
}
removeEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function f0(e:Event):void
{
array[i].rotation += 90;
}
}
}