Hi!
I defined a simple event class:
public class NewMoveEvent extends Event {
public function NewMoveEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=true)
{
super(type, bubbles, cancelable);
}
}
}
Then in custom mxml component, I defined a button which triggers it:
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:ns1="ui.*" layout="absolute" width="682" height="412" title="Board">
<mx:Metadata>
[Event(name="newformevent", type="events.NewMoveEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import events.NewMoveEvent;
import config.Config;
private function addNewUIComponent(event:Event):void
{
var e:NewMoveEvent = new NewMoveEvent("newformevent");
dispatchEvent(e);
}
]]>
</mx:Script>
<ns1:ChessBoard x="8" y="9" width="350" height="350" backgroundColor="0x99CCCC" moveId="0" name="chessboard" themeColor="#FFFFFF"/>
<mx:Button id="next" x="507" y="127" label="Next" click="addNewUIComponent(event)"/>
<ns1:PieceContainer x="363" y="10" width="292" height="51" items="{Config.piecesWhite}" id="white"/>
<ns1:PieceContainer x="362" y="69" width="292" height="51" items="{Config.piecesBlack}" id = "black"/>
<ns1:PasteBin x="363" y="306" width="292" height="53" backgroundColor="0x99CCCC" id="paste"/>
<mx:Button x="445" y="127" label="Save" name="save" enabled="false"/>
No from the main application file I want to set the event handler, to this event. I can easily do it from mxml
e.g.
But cant do it in actionscript (e.g. this code don't work):
private function addNewUIContainer(event:Event):void
{
var newBoard:UIContainer = new UIContainer();
newBoard.addEventListener(NewMoveEvent.NEWFORMEVENT, addNewUIContainer);
}
Compiler gives me an error. Don't understand why.
ERROR
Access of possibly undefined property NEWFORMEVENT through a reference with static type Class.
And yes, UIContainer is mxml class
The function addNewUiContainer is defined in main file (project.mxml)