开发者

How to add image to sprite so TouchEvent responds?

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜