Using the hitArea
package
{
import flash.display.*;
import flash.events.*;
public class Main extends Sprite
{
public function Main()
{
var notHitArea:Sprite = new Sprite();
notHitArea.graphics.beginFill(0x00FF00, 1.0);
notHitArea.graphics.drawRect(0, 0, 30, 30);
notHitArea.graphics.endFill();
addChild(notHitArea);
notHitArea.x = 100;
notHitArea.y = 200;
var hitAreaSprite:Sprite = new Sprite();
hitAreaSprite.graphics.beginFill(0x0000FF, 1.0);
hitAreaSprite.graphics.drawRect(0, 0, 30, 30);
hitAreaSprite.graphics.endFill();
addChild(hitAreaSprite);
notHitArea.hitArea = hitAreaSprite;
hitAreaSprite.mouseEnabled = false;
notHitArea.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
}
private function clickHandler(mouseEvent:MouseEvent):void
{
trace(" clickHandler ");
}
}
}
Related examples in the same category