Code Behind in Flex
Wednesday, January 21, 2009
If you are a Asp.Net developer you are more interested in writing code behind file to separate logic from interface.
This is a simple example to show code behind in flex
CodeBehindTest.mxml
In the above code we included the code behind file in main mxml
This is actual code behind action script file
CodeBehindTest.as
Madhu :-)
This is a simple example to show code behind in flex
CodeBehindTest.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="initApp();">
<mx:Script>
<![CDATA[
include "CodeBehindTest.as";
]]>
</mx:Script>
<mx:Button id="btnMessage" label="Show Message"/>
</mx:Application>
In the above code we included the code behind file in main mxml
This is actual code behind action script file
CodeBehindTest.as
// ActionScript file
import flash.events.MouseEvent;
import mx.controls.Alert;
private function initApp():void
{
btnMessage.addEventListener(MouseEvent.CLICK,ShowMessage);
}
private function ShowMessage(e:MouseEvent):void
{
Alert.show("Message from codebehind");
}
Madhu :-)
Labels: Flex codebehind