Monday, February 9, 2009

Flex Basic components - source code

How to use Basic components, like button, combo box, grid, MessageBox(Alert Box), Radio Button, CheckBox, Text Box etc in Adobe Flex.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="632" height="291" creationComplete="init()">
<mx:Button x="479" y="25" label="Add to Grid" click="btn_Click()"/>
<mx:CheckBox x="37" y="36" id="chk_box" label="Checkbox" click="checkbox_Click()"/>
<mx:ComboBox x="267" y="25" width="189" id="combo_id" prompt="select">
<mx:dataProvider>
<mx:String>data 1</mx:String>
<mx:String>data 2</mx:String>
<mx:String>data 3</mx:String>
<mx:String>data 4</mx:String>
<mx:String>data 5</mx:String>
<mx:String>data 6</mx:String>
<mx:String>data 7</mx:String>
<mx:String>data 8</mx:String>
<mx:String>data 9</mx:String>
<mx:String>data 10</mx:String>
</mx:dataProvider>
</mx:ComboBox>
<mx:RadioButtonGroup id="radiogroup1" change="radiobtn_Click()"/>
<mx:RadioButton x="37" y="66" label="Button 1" groupName="radiogroup1"/>
<mx:RadioButton x="37" y="92" label="Button 2" groupName="radiogroup1"/>
<mx:ProgressBar x="267" y="213" width="247" id="prg_id"/>
<mx:TextInput x="37" y="122" id="text_id" change="{label_id.text ='InputBox Value =' + text_id.text}"/>
<mx:DataGrid x="267" y="54" id="datagrid1">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="slno"/>
<mx:DataGridColumn headerText="Column 2" dataField="cdata"/>
</mx:columns>
</mx:DataGrid>
<mx:Label x="37" y="152" text="Input box value" id="label_id"/>

<mx:Script>
<![CDATA[
import mx.messaging.messages.ErrorMessage;
import mx.collections.ArrayCollection;
import mx.controls.List;
public var arr:ArrayCollection=new ArrayCollection();
private var i:int;


import mx.controls.Alert;
private function init():void{
i=0;
prg_id.maximum=10;
}
private function checkbox_Click():void{
//if(chk_box.selected
Alert.show("Check box " + chk_box.selected);
}

private function radiobtn_Click():void{
Alert.show(" Radio " + radiogroup1.selectedValue + "selected");
}
private function btn_Click():void{
if(combo_id.selectedIndex==-1)
Alert.show("Please select a value from ComboBox" , "Flex Tutorial");
else{
var obj:Object=new Object();
Alert.show(combo_id.selectedItem.toString());
obj.cdata=combo_id.selectedItem;
obj.slno=i;
arr.addItem(obj);
datagrid1.dataProvider=arr;
prg_id.setProgress(i,10);
if(i < 11)
i++;

}
}
]]>
</mx:Script>

</mx:Application>

Output File

No comments:

Post a Comment