View Full Version : Bitmaps not clickable?
praufet
01-11-2007, 11:23 PM
Are Bitmaps not clickable? I have the following code just as a test and nothing happens. Even though bitmaps inherit from the eventdispatcher. A contentloaderinfo seems to be clickable though. What gives?
import flash.display.*;
import flash.events.*;
var bmd:BitmapData = new BitmapData(100,100,false,0xFFFF9900);
var bmp:Bitmap = new Bitmap(bmd)
bmp.addEventListener(Event.SELECT,test);
addChild(bmp);
function test(){
trace("test");
}
trybmp.addEventListener( MouseEvent.CLICK, test );
dr_zeus
01-12-2007, 12:32 AM
You should use the MouseEvent.CLICK event if you want to capture mouse clicks. See changes:.
import flash.display.*;
import flash.events.*;
var bmd:BitmapData = new BitmapData(100,100,false,0xFFFF9900);
var bmp:Bitmap = new Bitmap(bmd)
bmp.addEventListener(MouseEvent.CLICK,test);
addChild(bmp);
function test(event:MouseEvent){
trace("test");
}
Also, when you're working with event listeners, you should remember to pass the event as a parameter.
praufet
01-12-2007, 06:29 AM
sorry I had that, but changed it to try a few things out. I keep forgetting to put the event as a parameter. I'll try that tomorrow.
[update]
Tried this code
import flash.display.*;
import flash.events.*;
var bmd:BitmapData = new BitmapData(100,100,false,0xFFFF9900);
var bmp:Bitmap = new Bitmap(bmd)
bmp.addEventListener(MouseEvent.CLICK,test);
addChild(bmp);
function test(evt:Event){
trace("test");
}
Still doesn't work.
praufet
01-12-2007, 09:36 PM
So after reading the as3 doco for a few hours I figured it out. Bitmap doesn't inherit the click method. So instead you have to do this.
import flash.display.*;
import flash.events.*;
var bmd:BitmapData = new BitmapData(100,100,false,0xFFFF9900);
var bmp:Sprite = new Sprite()
bmp.graphics.beginBitmapFill(bmd,null,false);
bmp.graphics.drawRect(0,0,bmd.width,bmd.height)
bmp.addEventListener(MouseEvent.CLICK,test);
addChild(bmp);
function test(evt:MouseEvent){
trace("test");
}
Hope this can help some people in the future.
ah yeah it don't extend InteractiveObject.
after reading the as3 doco for a few hours I figured it out
Its pretty easy to find what events are supported. look up the class your enquirig about and look what events are listed.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.