I create my sprite and event listener like this:
public function init():void
{
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x336699);
mySprite.graphics.drawRect(100,100,150,50);
addChild(mySprite);
mySprite.addEventListener(TouchEvent.TOUCH_BEGIN, start);
}
private function start(event:TouchEvent):void
{
// do stuf开发者_StackOverflow中文版f
}
But how would I add an image to the sprite so that the TouchEvent responds to touching the image?
Create the image (e.g. using a Bitmap) and add it to mySprite using addChild().
The events use a special sequence of "bubbling" up and down the display list so a touch triggered in the child of a sprite will trigger the event in the parent (and on the stage, etc.)
精彩评论