views:

344

answers:

1

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

            }   
        }
+2  A: 

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

jeremynealbrown
O, I was looking at the docs and it said it inherited EventDispatcher, so plus it showed one its methods being addEventlistner. Not sure why. But I am trying to be light as possible. I am tiling and using sprites slow down my scrolling. is there a better solution ?
numerical25
@numerical25: Keep reading the documentation, and you'll see that just because something is an EventDispatcher, doesn't mean that it reacts to mouse events. All display objects are event dispatchers, to be able to dispatch events such as ADDED_TO_STAGE and REMOVED_FROM STAGE.
richardolsson
yea but it also showed addeventlistner as a method http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Bitmap.html . not saying that you guys are wrong. I completely agree. but it just threw me off a little. but thanks for your help. I appreciate it alot.
numerical25
jeremynealbrown