Add a mouse event listener to a bitmap using ActionScript 3
I'm new to ActionScript 3 (no Flash development experience) and was wondering how I would use adding a mouse event listener to a bitmap ? The code works with a sprite, not a bitmap. Here is a shorthand 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.
+2
Antigony
source
to share
2 answers
You have added an event listener to the fsImage.addEventListener (...
Now you need to write a function that handles this event, for example:
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);
+9
source to share