Hi Andew,
Just a month ago Jason posted a very very usefull note on how to write custom events.

See below:


Here is how you write a custom event:

package
{
import flash.events.Event;

public class MyEvent extends Event
{
public static var SOUND_REQUESTED:String =
"sound_requested";

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

}

public override function clone():Event
{
return new MyEvent(type, bubbles, cancelable);
}

public override function toString():String
{
return formatToString("MyEvent", "type",
"bubbles", "cancelable", "eventPhase");
}

}

}

Here is how you would dispatch that event with bubbling:

dispatchEvent(new MyEvent(MyEvent.SOUND_REQUESTED, true));

Here is how you would listen for it and handle it anywhere in the
display chain:

addEventListener(MyEvent.SOUND_REQUESTED, onSoundRequested);

function onSoundRequested(event:MyEvent):void
{
//Code to play sound here.
}


HTH
Willem van den Goorbergh
On 27-okt-2009, at 17:56, Dave Watts wrote:

Why can't I add any properties to an AS3 Event object? I get a 1056: cannot
create property prop-name on Event....
Event extends Object, right?

Event is not a dynamic class. In AS3, you can only add properties to
dynamic classes. So, as everyone else has mentioned, you have to
extend Event to create a custom event class. Don't forget to override
the clone method and create a new event!

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!

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



=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Geografiek is a Dutch, Utrecht-based map and chart design company.
Willem van den Goorbergh can be contacted by telephone: (+31) 30-2719512 or cell phone: (+31)6-26372378
or by fax: (+31)302719687
snail mail: Hooghiemstraplein 89 3514 AX UTRECHT
Visit our website at: http://www.geografiek.nl
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=




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

Reply via email to