//myEvents\events\TestEvent.as
package myEvents
. events
{
// Writed by Aslan Shek
// http://www.slsay.com/archives/25
import flash.events . Event ;
public class TestEvent extends Event
{
public static const EVENT_A : String = "eventA" ;
public static const EVENT_B : String = "eventB" ;
public function TestEvent ( type : String )
{
super ( type ) ;
}
}
}
{
// Writed by Aslan Shek
// http://www.slsay.com/archives/25
import flash.events . Event ;
public class TestEvent extends Event
{
public static const EVENT_A : String = "eventA" ;
public static const EVENT_B : String = "eventB" ;
public function TestEvent ( type : String )
{
super ( type ) ;
}
}
}
//myEvents\TestEventComp.mxml
<?xml version="1.0" encoding="utf-8" ?>
<!-- http://www.slsay.com/archives/25 -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="300" >
<mx:Script>
<![CDATA[
// http://www.slsay.com/archives/25
import myEvents.events.TestEvent;
]]>
</mx:Script>
<mx:Metadata >
[Event(name="eventA", type="myEvents.events.TestEvent")]
</mx:Metadata >
<mx:Button label="Test Event"
click="dispatchEvent(new TestEvent(TestEvent.EVENT_A));" />
</mx:Canvas >
<!-- http://www.slsay.com/archives/25 -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="300" >
<mx:Script>
<![CDATA[
// http://www.slsay.com/archives/25
import myEvents.events.TestEvent;
]]>
</mx:Script>
<mx:Metadata >
[Event(name="eventA", type="myEvents.events.TestEvent")]
</mx:Metadata >
<mx:Button label="Test Event"
click="dispatchEvent(new TestEvent(TestEvent.EVENT_A));" />
</mx:Canvas >
//test.mxml
<? xml
version =
"1.0" encoding=
"utf-8"
?>
<!-- http : //yecon.blog.hexun.com/28759584_d.html -->
< mx : Application xmlns : mx= "http://www.adobe.com/2006/mxml"
layout= "absolute"
xmlns : myEvents= "myEvents.*" >
< mx : Script >
<! [ CDATA [
// Writed by Aslan Shek
// http://www.slsay.com/archives/25
import myEvents . events . TestEvent ;
private function testEventHandler ( evt : TestEvent ) : void
{
trace ( "asdf" ) ;
}
] ] >
</ mx : Script >
< myEvents : TestEventComp eventA= "testEventHandler(event);" />
</ mx : Application >
<!-- http : //yecon.blog.hexun.com/28759584_d.html -->
< mx : Application xmlns : mx= "http://www.adobe.com/2006/mxml"
layout= "absolute"
xmlns : myEvents= "myEvents.*" >
< mx : Script >
<! [ CDATA [
// Writed by Aslan Shek
// http://www.slsay.com/archives/25
import myEvents . events . TestEvent ;
private function testEventHandler ( evt : TestEvent ) : void
{
trace ( "asdf" ) ;
}
] ] >
</ mx : Script >
< myEvents : TestEventComp eventA= "testEventHandler(event);" />
</ mx : Application >