If I have a simple class that has a rectangle:
package
{
import flash.display.Sprite;
import flash.geom.Rectangle;
public class Spot extends Sprite
{
private var __rect:Rectangle;
public function Spot()
{
init();
}
private function init():void
{
__rect = this.getRect(this);
}
public function get rect():Rectangle{
return __rect;
}
}
}
And I animate an instance of this class on the stage and try to trace it’s coordinates:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class RectangleTest extends Sprite
{
public var spot:Spot = new Spot();
public function RectangleTest()
{
init();
}
private function init():void
{
addEventListener(Event.ENTER_FRAME, dynamicSpotTrace, false, 0, true);
}
private function dynamicSpotTrace(e:Event):void
{
trace(spot.rect.x, spot.rect.y, spot.rect.width, spot.rect.height);
}
}
}
The output traces:
0 0 65 65
Over and over (since the Spot has a registration point of 0,0)…how can I rewrite this so I can get the new coordinates of the Spot instance at every frame (since the spot is actually moving across the screen??)
With taskinoor’s answer in mind, you can do it a lot easier.