开发者

BitMap Eventlistener not working

开发者 https://www.devze.com 2022-12-15 09:35 出处:网络
I am trying to add an event listener to my BitMap. Tile extends gameProps, which extends BitMap. I try using addEventListener. That doesnt work. but the Adobe docs say that Bitmap has an addEventListe

I am trying to add an event listener to my BitMap. Tile extends gameProps, which extends BitMap. I try using addEventListener. That doesnt work. but the Adobe docs say that Bitmap has an addEventListener object.

 package {
            import flash.display.BitmapData;
            import flash.events.*;
            import flash.events.MouseEvent;
            import flash.geom.Rectangle;
            import flash.geom.Point;

            public class Tile extends gameProps {

       开发者_StackOverflow社区         public var tileNum:Number = 0;


                public function Tile(tileNumber:Number):void
                {
                    tileNum = tileNumber;           
                    addEventListener(MouseEvent.MOUSE_OVER, respond);
                }


                public function respond(e:MouseEvent):void
                {   trace("HELLO");             
                }

            }   
        }


The Bitmap class extends the DisplayObject not the InteractiveObject and can therefore not receive mouse events. Try wrapping the bitmap object in a Sprite sub-class. Something like this (pseudo-code):

public class Image extends Sprite
{
     var bitmap:Bitmap;

     public function Image()
     {
         bitmap = new Bitmap();
         addChild( bitmap );
     }
}

InteractiveObject Docs: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/InteractiveObject.html

0

精彩评论

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