I have a class TestOverride that implements IOverride. This class is
dispatching event. I am trying to handle this event in application
that contains states definition with one state that has TestOverride
added, but to no avail.
Why am I not able to capture this event?
Here is my code, it is very simple:
1. TestOverride
package org.testEvents
{
import flash.display.*;
import flash.events.Event;
import mx.core.*;
import mx.states.*
public class TestOverride extends Shape implements IOverride
{
public function TestOverride()
{
}
public function initialize():void{
}
public function apply(parent:UIComponent):void
{
this.execute();
}
public function remove(parent:UIComponent):void
{
//TODO: implement function
}
public function execute():void{
trace("execute")
dispatchEvent(new Event("testEvent",true))
}
}
}
2. Application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:t="org.testEvents.*"
layout="absolute">
<mx:Script><![CDATA[
protected override function initializationComplete():void{
addEventListener("testEvent", handleIt)
currentState = "start"
super.initializationComplete()
}
public function handleIt(event:Event):void{
trace("event handled")
}
]]></mx:Script>
<mx:states>
<mx:State name="start">
<t:TestOverride />
</mx:State>
</mx:states>
</mx:Application>
When I debug the application, discpatchEvent is called and word
"execute" written to console.