|
Athing needs a script block that imports
the MyEvents.EnableChangedEvent. Matt From: Hi, I’ve been trying to
implement a custom event but get the following compile time error. Type annotation is not a
compile-time constant:MyClassName To be honest the whole
thing was botched pretty quickly but given all the code is cut and paste from
the help docs I’m stuck as to how to properly implement a custom event
class. In my application script
tag … <![CDATA[
import MyEvents.EnableChangedEvent;
public function doit(eventObj:MyEvents.EnableChangedEvent)
{
trace("yo = " + eventObj.isEnabled);
}
]]> … Component event captured
and told to pass event to doit() method above. … <Athing
buttoned="doit(event)">
</Athing> The Athing component <?xml
version="1.0" encoding="utf-8"?> <mx:Canvas
xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*"
xmlns:yo:"MyEvents.EnableChangedEvent">
<mx:Metadata>
[Event(name="buttoned", type="MyEvents.EnableChangedEvent")]
</mx:Metadata>
<mx:Button click="dispatchEvent(new
MyEvents.EnableChangedEvent('buttoned'))"/>
<mx:Text x="71" y="0" text="hello">
</mx:Text> </mx:Canvas> The my event class // ActionScript file package MyEvents {
import flash.events.Event;
public class EnableChangedEvent extends Event
{
static public BUTTONED:String = "buttoned";
// Public constructor.
public function EnableChangedEvent(type:String,
isEnabled:String="")
{
// Call the constructor of the superclass.
super(type);
// Set the new property.
this.isEnabled = isEnabled;
}
// Define a public variable to hold the state of the enable property.
public var isEnabled:String;
// Override the inherited clone() method.
override public function clone():Event {
return new EnableChangedEvent(type, isEnabled);
} } }
|

