Hi,
basically, I’m having trouble with the hitTestPoint method. As soon as I move the root of the swf, it no longer works as it should.
To see what I mean, run this code:
package todd.test
{
import flash.display.MovieClip
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import com.containers.ContentScroller;
public class Main extends MovieClip
{
private var block:Sprite = new Sprite();
private var dummyBlock:Sprite = new Sprite();
public function Main():void
{
block.graphics.beginFill(0x00C000);
block.graphics.drawRect(-50, -50, 100, 100);
block.graphics.endFill();
addChild(block);
dummyBlock.graphics.beginFill(0x00C000, 0.2);
dummyBlock.graphics.drawRect(-50, -50, 100, 100);
dummyBlock.graphics.endFill();
this.addEventListener(Event.ADDED_TO_STAGE, added);
}
private function added(e:Event):void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
stage.addEventListener(Event.RESIZE, resize);
stage.addChild(dummyBlock);
}
private function resize(e:Event):void
{
this.x = stage.stageWidth* 0.5;
this.y = stage.stageHeight * 0.5;
}
private function stageMouseUp(e:MouseEvent):void
{
var point:Point = new Point(stage.mouseX, stage.mouseY);
trace("Stage Click", point, block.globalToLocal(point));
trace("hit?", block.hitTestPoint(point.x, point.y));
}
}
}
Click the square, everything works as normal. Then resize the stage and try clicking it again, no such luck. But the “ghost” square works when clicked on.
I would just pass in the root as the coords (which seems to work every time), but at some points I don’t have a reference to the root.
Does the root always have to be at (0, 0) for this function to work? or is there anyway I can compensate for it?
Cheers!