I’m so use to timeline code, that this baffles me. How do I get a button
class to recognize a button instance on stage?
Please help.
…Just revised
Buttons.fla
Class: 'Buttons'
Button with instance name placed on stage
Buttons.as
package {
import flash.display.MovieClip;
public class Buttons extends MovieClip {
public function Buttons() {
mc.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
stage.addChild(this);
}
public function onClick(event:MouseEvent):void{
trace("Hello World");
}
}
}
Error:
1120: undefined property
The error indicates it’s the mouse event, not my instance name mc.
You are missing a curly brace and a definition of mc and an import of MouseEvent (the root of your problem above):
Of course, there are several other/better ways to accomplish these same results, but that should at least fix your compile problem. Now, to get this on stage, you need to add it to something that exists. One simple way to do that is by putting the following line right below this.addEventListener:
If you have other questions on getting this to work, let me know. I hope that points you in the right direction,
–gMale
EDIT:
In response to the comments below here is a link to the Flash files. I tried to follow the intent of what you were doing. There’s one quick clickable button coded within the IDE and one quick clickable button coded in a separate *.AS file: