Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitMap Eventlistener not working

Tags:

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 {

                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");             
                }

            }   
        }
like image 577
numerical25 Avatar asked Jan 01 '10 06:01

numerical25


1 Answers

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

like image 200
JeremyFromEarth Avatar answered Oct 03 '22 22:10

JeremyFromEarth