开发者

How to add image to sprite so TouchEvent responds?

开发者 https://www.devze.com 2023-03-02 12:36 出处:网络
I create my sprite and event listener like this: public function init():void { var mySprite:Sprite = new Sprite();

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

精彩评论

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