views:

405

answers:

1

Hi, I'm new to ActionScript 3 (without any experience with Flash development) and I was wondering how I would go about adding an mouse event listener to a bitmap? The code works with a sprite, just not with a bitmap. Here is a shortened version of the code I'm trying to run, I hope it makes sense!

var fsImageRequest:URLRequest = new URLRequest("img/fullscreen.png");
var fsImageLoader:Loader = new Loader();
fsImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fsImageLoaded);
fsImageLoader.load(fsImageRequest);
addChild(fsImageLoader);

function fsImageLoaded(e:Event):void {
    var fsImageLoader:Loader = Loader(e.target.loader);
    fsImage = Bitmap(fsImageLoader.content);
    fsImage.addEventListener(MouseEvent.CLICK, fullScreenClick)
}

Thanks in advance.

+3  A: 

You've added the event listener in the line fsImage.addEventListener(...

Now you need to write the function that handles that event, such as:

private function fullScreenClick(event:MouseEvent):void
{
  // do something here
}

EDIT: To add a bitmap to a sprite, you can do the following:

var sprite: Sprite = new Sprite();
sprite.addChild(fsImage);
addChild(sprite);
Michael Todd
Hi, thanks for the reply! Unfortunately I already have a function to handle the event - it works with a sprite or a textfield, just not a bitmap. Is there a way I can make a bitmap act as a sprite?
What exactly are you trying to do with the bitmap?
Michael Todd
I want to be able to run a mouse event on it. Is there a way I can encapsulate it within a sprite?
Thank you for your help!