Tuesday, July 13, 2010

Dynamic XML generate in Flex

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  backgroundColor="#ffffff" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public var yVal:int=0;
public var syVal:int=0;
public var i:int=0;
private var dataxml:XML;
private var datalist:XML=new XML(<data/>);
private var xxx:XMLList=new XMLList();
    public function add():void
    { 
   
dataxml=new XML(<employee/>);
dataxml.@Sys=tex1.text;
dataxml.@Mb=tex2.text;
dataxml.@Hd=tex3.text;
dataxml.@Ra=tex4.text;
dataxml.@Sm=tex5.text;
dataxml.@Re=tex6.text;
datalist.appendChild(dataxml);
xxx=new XMLList(datalist.children());

data.dataProvider=xxx;
Alert.show("DATAS SEND SUCCESSFULLY");

    }
    public function clr():void
    {
    tex1.text=''
    tex2.text=''
    tex3.text=''
    tex4.text=''
    tex5.text=''
    tex6.text=''
    }
    
    public function search():void
{
if(datalist.employee.length()<1)
{
Alert.show("List Empty");
}
  
for(var j:int=0;j<datalist.employee.length();j++)
{
if(searchT.text==datalist.employee[j].@Sys)
{
//datacomp=new data_comp();
//searchCan.addChild(datacomp);
tex1.text=datalist.employee[j].@Sys;
   tex2.text=datalist.employee[j].@Mb;
tex3.text=datalist.employee[j].@Hd;
         tex4.text=datalist.employee[j].@Ra;
tex5.text=datalist.employee[j].@Sm;
tex6.text=datalist.employee[j].@Re;
//tex1.x=0;
//tex1.y=syVal;
//syVal=syVal+tex1.height;
}

else
{
Alert.show("Nothing Found");
}
    
  }
 
  }
]]>
</mx:Script>






<mx:Iris id="irisOut" duration="1000" showTarget="true"/>
    <mx:Iris id="irisIn" duration="1000" showTarget="false"/>


   <mx:Panel id="pan"  x="426" y="207" width="579" height="446" layout="absolute" horizontalScrollPolicy="auto" includeInLayout="true" paddingBottom="30" borderThickness="5" borderColor="black" cornerRadius="15" backgroundColor="#90877F">
      <mx:Form visible="true" x="69" y="16" height="184" width="410.5" fontWeight="bold">
      <mx:FormItem label="SYSTEM NO" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex1"/>
      </mx:FormItem>
      <mx:FormItem label="MOTHER BOARD" fontWeight="bold" width="290" fontSize="12">
      <mx:TextInput id="tex2" width="163"/>
      </mx:FormItem>
      
      <mx:FormItem label="HDD" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex3"/>
      </mx:FormItem>
      <mx:FormItem label="RAM" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex4"/>
      </mx:FormItem>
      <mx:FormItem label="SMPS" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex5"/>
      </mx:FormItem>
    
      </mx:Form>
   
      <mx:TextArea id="tex6" fontWeight="bold" color="blue" x="57" y="233" height="118" width="407.5"/>
      <mx:Label x="57" y="202" text="Report" fontWeight="bold" fontSize="14" textDecoration="underline"/>
      <mx:HBox x="89.5" y="368" width="353" height="28">
         <mx:Button id="but1" click="add()" label="Save"/>
         <mx:Button id="but2" click="clr()" label="Clear"/>
         <mx:TextInput id="searchT" width="137"/>
         <mx:Button click="search()" label="Search"/>
      </mx:HBox>
      <mx:DataGrid   id="data"  width="559" height="396" visible="{cb1.selected}"
            showEffect="{irisIn}" hideEffect="{irisOut}" borderStyle="outset"  alpha="1.0" dropShadowColor="black" dropShadowEnabled="true" shadowDirection="right" shadowDistance="5" editable="true" fontWeight="bold" x="0" y="10">
         <mx:columns>
            <mx:DataGridColumn headerText="SYSTEM NO" dataField="@Sys"/>
            <mx:DataGridColumn headerText="MOTHER BOARD" dataField="@Mb"/>
            <mx:DataGridColumn headerText="HDD" dataField="@Hd"/>
            <mx:DataGridColumn headerText="RAM" dataField="@Ra"/>
            <mx:DataGridColumn headerText="SMPS" dataField="@Sm"/>
            <mx:DataGridColumn headerText="REPORT" dataField="@Re"/>
         </mx:columns>
      </mx:DataGrid>
   </mx:Panel>
   <mx:ApplicationControlBar width="579" height="31" cornerRadius="15" fillColors="black" barColor="black" fillAlphas="[0.55, 0.54]" alpha="1.0" color="black" x="426" y="207">
      <mx:CheckBox  id="cb1" label="View Data" selected="false" color="#080808" fontWeight="bold"/>
      <mx:HRule shadowColor="gray" strokeColor="gray" alpha="0.0"/>
      <mx:Label text="COALESCE TECHNOLOGIES" width="229" fontWeight="bold" fontSize="12" color="#0F0FF3"/>
   </mx:ApplicationControlBar>
   


</mx:Application>


SCREEN SHOT &  DEMO HERE





No comments:

Post a Comment