I’m having a challenge getting an event listener to use the target of the click to trigger a method of a custom class… probably easier to show in this super stripped down version. Here’s the class:
package {
import flash.display.*;
public class MyClass extends MovieClip {
public var newObject:MovieClip;
public function MyClass(whichClass:Class, whereToAdd:Object):void {
newObject = new whichClass();
whereToAdd.addChild(newObject);
newObject.x=200;
newObject.y=200;
}
public function hello():void {
trace("HELLO WORLD");
}
}
}
and here’s the fla (which has one movie clip in the library… a simple box with a class of “square”):
var mySquare:square = new square();
var myObject:MyClass = new MyClass(square, this);
myObject.hello(); // this traces "HELLO WORLD"
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
function mouseHandler(evt:Event):void {
trace("clicked");
evt.target.hello(); // this throws an error: "hello is not a function" instead of tracing "HELLO WORLD"
}
Any brains out there that can give some input?