You might wanna read the docs for some basics on Events in AS3:
http://livedocs.adobe.com/flash/9.0/main/00000138.html
http://livedocs.adobe.com/flash/9.0/main/00000139.html

When writing cusom events, you can usually ommit the bubbles and cancellable 
arguments, as those are false by default.

And you should always implement a clone() method:

<quote>
Event class utility methods

There are two utility methods in the Event class. The clone() method allows you to create copies of an event object. The toString() method allows you to generate a string representation of the properties of an event object along with their values. Both of these methods are used internally by the event model system, but are exposed to developers for general use.

For advanced developers creating subclasses of the Event class, you must override and implement versions of both utility methods to ensure that the event subclass will work properly.
</quote>

AFAIK, the toString() method is only useful for debugging purposes (trace).

----- Original Message ----- From: "Cor" <c...@chello.nl>
To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, December 18, 2008 11:27 PM
Subject: RE: [Flashcoders] Custom eventListener


Thanks Ross and Jason!

Now I understand this.
But I am trying to imagine when I would use a custom event.
I have no idea?
Could you give an example?

Kind regards
Cor

-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Merrill,
Jason
Sent: donderdag 18 december 2008 23:20
To: Flash Coders List
Subject: RE: [Flashcoders] Custom eventListener

To add on to David's fine reply, Ross, you're close, but not quite - this is
how I write custom events, I think you'll want to do something like this
instead - this works great for me:

To write the event:

package events
{
import flash.events.Event;

public class MyEvent extends Event
{
public static var MYEVENT1:String = "myEvent1";
public static var MYEVENT2:String = "myEvent2";

public function MyEvent(type:String, bubbles:Boolean =
false, cancellable:Boolean = false )
{
super(type, bubbles, cancelable);
}

}

}

Then to dispatch:

import events.MyEvent;

dispatchEvent(new MyEvent(MyEvent.MYEVENT2, false, true));


Then to listen and react to dispatch:

myObject.addEventListener(MyEvent.MYEVENT2, onMyEvent2)

public function onMyEvent2(event:MyEvent):void
{
Trace("myEvent2 heard!");
}


Jason Merrill
Bank of America     Instructional Technology & Media   ยท   GCIB & Staff
Support L&LD


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to