Reputation: 67
let's say that i have this button which is called "Click_Here" and i added an event listener to it in some class file in order for it to run the event handler in a different one .. so it will be like this
classfile1.as
Click_Here.addEventListner(MouseEvent.CLICK , buttonClicked ) ;
classfile2.as
public function buttonClicked (e:MouseEvent){ trace ("hello");}
is that possible .. ?
Upvotes: 1
Views: 100
Reputation: 2228
Refer
o'reilly essential actionscript 3.0. book.
That will give you clear clarity.
Upvotes: 0
Reputation: 46027
Yes. Consider the class:
public class MyClass
{
public function MyClass()
{
}
public static function staticListener(evt:MouseEvent):void {
trace("static");
}
public function instanceListener(evt:MouseEvent):void {
trace("instance");
}
}
Now do this:
Click_Here.addEventListner(ouseEvent.CLICK , MyClass.staticListener);
Or:
var obj:MyClass = new MyClass();
Click_Here.addEventListner(ouseEvent.CLICK , obj.instanceListener);
Upvotes: 3
Reputation: 18820
yes, that's possible:
Click_Here.addEventListner(MouseEvent.CLICK , instanceOfClass2.buttonClicked ) ;
Upvotes: 2