hussein
hussein

Reputation: 67

putting the event listener in different class ..?

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

Answers (3)

Benny
Benny

Reputation: 2228

Refer

o'reilly essential actionscript 3.0. book.

That will give you clear clarity.

Upvotes: 0

taskinoor
taskinoor

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

Philipp Kyeck
Philipp Kyeck

Reputation: 18820

yes, that's possible:

Click_Here.addEventListner(MouseEvent.CLICK , instanceOfClass2.buttonClicked ) ;

Upvotes: 2

Related Questions