-
I need to know when an instance of a class is clicked
I know how to do this if the object to be clicked isn't an instance of a class i.e.:
missile.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
But what do I do if "missile" is a class object? Using above code I get an error because when the project is opened there aren't any instances of it to begin with. What changes do I make to above line and should it go in the main code or in the missile class code?
I also tried the below line in the class code for "missile" class but again it didn't work.
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
-
.
Hi,
I'm not sure what you mean, attach your files or a rough mock up
-
.
Hi,
If you mean calling it from the library when its not on the stage, then something like so
PHP Code:
import flash.events.MouseEvent;
var missil:missile = new missile();
addChild(missil);
missil.x = 50;
missil.y = 50;
missil.buttonMode = true;
missil.addEventListener(MouseEvent.MOUSE_DOWN, mouseIsDown);
function mouseIsDown(e:MouseEvent):void
{
trace(e.target);
}
-
I didn't explain it well but I found out the solution but thanks anyway. I put the following line in the constructor code for the missile class:
addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|