Tuesday, May 24, 2011

About for, for..in and for each..in Statement

for

The for loop allows you to iterate through a variable for a specific range of values. You must supply three expressions in a for statement: a variable that is set to an initial value, a conditional statement that determines when the looping ends, and an expression that changes the value of the variable with each loop. For example, the following code loops five times. The value of the variable i starts at 0 and ends at 4, and the output will be the numbers 0 through 4, each on its own line.

var i:int;
for (i = 0; i < 5; i++)
{
    trace(i);
} 
 
for..in 
 
The for..in loop iterates through the properties of an object, or the elements of an array. For example, you can use a for..in loop to iterate through the properties of a generic object (object properties are not kept in any particular order, so properties may appear in a seemingly random order):

var myObj:Object = {x:20, y:30}; 
for (var i:String in myObj) 
trace(i + ": " + myObj[i]); 

// output: 
// x: 20
// y: 30 

You can also iterate through the elements of an array:
var myArray:Array = ["one", "two", "three"];
 for (var i:String in myArray)
trace(myArray[i]); 

// output: 
// one
// two 
// three 

What you cannot do is iterate through the properties of an object if it is an instance of a user-defined class, unless the class is a dynamic class. Even with instances of dynamic classes, you will be able to iterate only through properties that are added dynamically.
 
 
for each..in 

The for each..in loop iterates through the items of a collection, which can be tags in an XML or XMLList object, the values held by object properties, or the elements of an array. For example, as the following excerpt shows, you can use a for each..in loop to iterate through the properties of a generic object, but unlike the for..in loop, the iterator variable in a for each..in loop contains the value held by the property instead of the name of the property:

var myObj:Object = {x:20, y:30}; 
for each (var num in myObj) 
{
trace(num); 
}
// output:
// 20 
// 30

You can iterate through an XML or XMLList object, as the following example shows:

var myXML:XML = <users> <fname>Jane</fname> <fname>Susan</fname> <fname>John</fname> </users>;
for each (var item in myXML.fname) 
{
trace(item);
}

/* output Jane Susan John */ 

You can also iterate through the elements of an array, as this example shows:

var myArray:Array = ["one", "two", "three"]; 

for each (var item in myArray) 
{
trace(item);
}

// output: 
// one
// two 
// three

You cannot iterate through the properties of an object if the object is an instance of a sealed class. Even for instances of dynamic classes, you cannot iterate through any fixed properties, which are properties defined as part of the class definition.


For Example

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script
        >
        <![CDATA[
            import mx.controls.Alert;
           
            public function foreachfun():void
            {
                var myArray:Array = ["one", "two", "three"];
                   
                    for each (var item in myArray)
                    {
                        Alert.show(item);
                    }
                   
                }
               
                public function forloopfun():void
                {
                    var myArray:Array = ["one", "two", "three"];
                       
                        for (var i:String in myArray)
                        {
                            Alert.show(myArray[i]);
                        }

                }
                public function xmlfileforeach():void
                {
                    var myXML:XML = <users>
                     <fname>Jane</fname>
                     <fname>Susan</fname>
                     <fname>John</fname>
                      <fname>Susan1</fname>
                     <fname>John1</fname>
                    </users>;
                   
                    for each (var item in myXML.fname)
                    {
                        Alert.show(item);
                    }
                }
               
                public function custom():void
                {
                    var sam:Array=new Array("kaniskar","Banupriya","Banu");
                   
                    for each(var j in sam)
                    {
                        Alert.show(j);
                       
                        if(j=="Banupriya")
                        {
                            trace("True");
                            break;
                        }
                    }
                }
               
               
        ]]>
    </mx:Script>
   
    <mx:Button x="378" y="397" label="For each Loop" click="foreachfun();"/>
    <mx:Button x="378" y="427" label="For Loop" click="forloopfun();"/>
    <mx:Button x="378" y="457" label="For each" click="xmlfileforeach();"/>
        <mx:Button x="378" y="487" label="Break" click="custom();"/>
   
</mx:Application>
 





Monday, April 25, 2011

Editable Tree Node (Single Click Funtion and Right Click Edit)

MXML File
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="functinality();"  layout="absolute" minWidth="1024" minHeight="768" backgroundColor="#FFFFFF">
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            import mx.controls.Tree;
            import mx.events.ListEvent;
           
             public var parentxml:XML;
           
           
            /* Tree Rename */
           
            [Bindable]
            private var treeData: XML = <tree>
                <node label="First Node">
                    <node label="Business Form_1" id="0" name="first"/>
                    <node label="Business Form_2" name="first"/>
                </node>
   
                </tree>
           
             private var retuxmlstru:XML;
           
         
             public function retuxmlfile():void
              
               {
             
               parentxml= XML(treeControl.selectedItem).parent();
               Alert.show(parentxml);
             
             
               }
               
              protected function tree1_itemEditBeginningHandler(event:ListEvent):void
       
                {
                    event.preventDefault();
           
                         }
                
               private function appComplete (event:ListEvent):void
              
               {
                  
              
                var menu1:RightClickMenu = new RightClickMenu ();
                menu1.AddItem("Edit", function ():void {treeControl.editable=true; Tree( event.target ).editedItemPosition = { columnIndex: 0, rowIndex: event.rowIndex };});
                menu1.AssignRightClick(treeControl);
             
                }  
               
                public function samplecheck(event:ListEvent):void
                {
                    treeControl.editable=false;
                     Alert.show("This is Single Click Function ");
                }
               
                public function functinality():void
                {
                    treeControl.addEventListener(ListEvent.ITEM_CLICK, samplecheck);
                    treeControl.addEventListener(ListEvent.ITEM_EDIT_BEGINNING,tree1_itemEditBeginningHandler)
                }
                    
        ]]>
       
    </mx:Script>
   
      <mx:Tree
        x="0" y="0" width="200" height="100%" id="treeControl"
        labelField="@label"
        showRoot="false"
        itemClick="appComplete(event)"
        itemFocusOut="retuxmlfile()"
        dataProvider="{treeData}"
        >
        </mx:Tree>
   
    <mx:Button x="58" y="476" label="Return XML" click="retuxmlfile()" />
       
       
</mx:Application>


Right Click Menu Component:-
RightClickMenu.as

package
{
    import flash.events.ContextMenuEvent;
    import flash.events.MouseEvent;
    import flash.ui.ContextMenuItem;
   
    import mx.core.Application;
    import mx.core.UIComponent;
   
    public class RightClickMenu
    {
        public var MenuContents:Array = new Array ();
       
        public  function RightClickMenu(){}

        public function AddItem (name:String, func:Function):void
        {
            MenuContents.push({Name:name, Func:func});
        }

        public function AssignRightClick (uiComponent:UIComponent):void
        {
            uiComponent.addEventListener(MouseEvent.MOUSE_OVER, genEnableMenu (uiComponent));
            uiComponent.addEventListener(MouseEvent.MOUSE_MOVE, disableMenu);
        }
       
        /* Assignment */
        private function ResetContextMenu (event:MouseEvent):void
        {    //remove menu
            Application.application.contextMenu.customItems = new Array ();       
            //remove this function
            Application.application.removeEventListener(MouseEvent.MOUSE_MOVE, ResetContextMenu);       
        }
       
        private function disableMenu(event:MouseEvent):void
        {   
            //Stop the mouse move event from propagating to the application level, where we remove the menu
            event.stopImmediatePropagation();           
        }
       
        private function genEnableMenu (uiComponent:UIComponent):Function
        {                       
            return function (event:MouseEvent):void
            {       
                //add event listener to remove the menu on mouse move               
                Application.application.addEventListener(MouseEvent.MOUSE_MOVE, ResetContextMenu);           
               
                //hide current menu
                Application.application.contextMenu.hideBuiltInItems();
               
                //remove menu (ifyou right click and then move, this may not be killed.
                Application.application.contextMenu.customItems = new Array ();               
               
                //create new menu
                for (var i:Number in MenuContents)
                {
                    var menuItem:ContextMenuItem = new ContextMenuItem(MenuContents[i].Name);
                    menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, MenuContents[i].Func);                                       
                    Application.application.contextMenu.customItems.push(menuItem);   
                }   
            }           
        }
       
        private function genClickCall (func:Function):Function
        {
            return function (event:ContextMenuEvent):void
            {   
                func()
                ResetContextMenu(null);
            }

        }

    }
}

Your File Keep in this Format;

Output:-



After Edit Node Return XML




Tuesday, March 29, 2011

Server side connection in flex using php

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#4D4B4B, #626060]">
<mx:Style source="assets/css/style.css"/>
<mx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;
        import mx.controls.Text;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import mx.controls.Alert;

     [Bindable]
     public var newuserloginDetail:NewuserLogin;
     public var alertmsgbox:alertpopup;
     public var displayhos:HospitalL2details;
     public var saml:XML;
    
     public function loginpage(evt:ResultEvent):void
     
     {
   
    if(evt.result.loginsuccess == "yes")

    {
        errorlogin.text="";
        username.text="";
          password.text="";
        displayhos=new HospitalL2details();
        this.addChild(displayhos);
    
     }

    if(evt.result.loginsuccess == "no")

     {
      username.text="";
      password.text="";
      errorlogin.text="Invalid username / password";

      }
       
     }
     
          private function login():void
   
      {
          loginHTTPservice.send();
      }
         
   
   
   
     public function createnewuser(evt:ResultEvent):void
     
     {
        
         if(evt.result.newuser == "Error")

    {
        newuserloginDetail.errormsg2.text="Error";
    
     }

    if(evt.result.newuser == "Successfully Created")

     {
     newuserloginDetail.errormsg2.text="Successfully Created";
     alertmsgbox=new alertpopup();
     PopUpManager.addPopUp(alertmsgbox,this,true);
     PopUpManager.centerPopUp(alertmsgbox);
      }
     
     }
     
     public function removemsgpopup():void
     
     {
     PopUpManager.removePopUp(alertmsgbox);   
     }
     
      public function removeallpopup():void
     
     {
     PopUpManager.removePopUp(alertmsgbox);   
      PopUpManager.removePopUp(newuserloginDetail);   
     }
     
     
     public function newuser():void
   
      {
          if(newuserloginDetail.newpassword.text != newuserloginDetail.newpassword1.text || newuserloginDetail.fname.text=="" || newuserloginDetail.lname.text=="" || newuserloginDetail.newpassword.text=="" || newuserloginDetail.newpassword1.text=="")
          {
             
            }
           
            else {
         
          createnewuserrequest.send();
           
            }
      }
     
      private function cleartexfield():void
      {
          errorlogin.text="";
          username.text="";
          password.text="";
      }   
     
      private function fault(evnt:FaultEvent):void
     
      {
          displayerrorHTTP.text=evnt.fault.faultString+'\n'+evnt.fault.faultCode+'\n'+evnt.fault.faultDetail;
      }
     
      public function newuserlogindis():void
     
      {
          newuserloginDetail=new NewuserLogin();
          PopUpManager.addPopUp(newuserloginDetail,this,true);
          PopUpManager.centerPopUp(newuserloginDetail);
     }
     
      public function romovepopupnewuser():void
      {
          PopUpManager.removePopUp(newuserloginDetail);
      }
      

    ]]>
   
</mx:Script>

<mx:HTTPService url="http://localhost/passwordresult/passoutput.php" useProxy="false" fault="fault(event)" result="loginpage(event)" method="POST" id="loginHTTPservice">

<mx:request xmlns="">
    <usernameres>{username.text}</usernameres>
    <passwordres>{password.text}</passwordres>
</mx:request>

</mx:HTTPService>

<mx:HTTPService url="http://localhost/passwordresult/newusercreate.php" method="POST" useProxy="false" result="createnewuser(event)" fault="fault(event)" id="createnewuserrequest">
   
    <mx:request xmlns="">
    <newusername>{newuserloginDetail.lname.text}</newusername>
    <newuserpass>{newuserloginDetail.newpassword.text}</newuserpass>
    </mx:request>
   
</mx:HTTPService>

    <mx:Panel x="406" y="241" width="453" height="287" layout="absolute" title="Login Page">
        <mx:Label x="52" y="59" text="User Name:" fontFamily="Arial" fontSize="13" fontWeight="bold"/>
        <mx:Label x="61" y="119" text="Password:" fontSize="13" fontFamily="Arial" fontWeight="bold"/>
        <mx:TextInput x="166" y="57" id="username"/>
        <mx:TextInput x="166" y="117" id="password" displayAsPassword="true"/>
        <mx:Button x="166" y="188" label="Submit" click="login()"/>
        <mx:Button x="271" y="188" label="Clear" click="cleartexfield();"/>
        <mx:Label x="20" y="219" text="New User Login" fontWeight="bold" buttonMode="true" useHandCursor="true" color="#0C8FAB" textDecoration="underline" click="newuserlogindis();"/>
        <mx:Label x="166" y="153" id="errorlogin" width="257" color="#ED1807"/>
    </mx:Panel>
    <mx:Label x="406" y="536" id="displayerrorHTTP" width="225" height="58" color="#FFFFFF"/>
   
</mx:Application>

HospitalL2details.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" backgroundColor="#4C4B4B">
<mx:Script>
    <![CDATA[
        import mx.core.Application;
        public function removethiscontainer():void
       
        {
            Application.application.removeChild(this);
        }
       
    ]]>
</mx:Script>

    <mx:Label x="24" y="14" text="Hospital Details" color="#F9FCFD" fontSize="16" fontFamily="Arial" fontWeight="bold"/>
    <mx:Label  right="10" y="19" buttonMode="true"  text="Logout" color="#FEFEFE" fontWeight="bold" fontFamily="Arial" fontSize="12" click="removethiscontainer();"/>
    <mx:Panel  left="10" right="10" top="64" y="57" width="100%" bottom="10" height="100%" layout="absolute" styleName="topspacepanel">
    </mx:Panel>
   
</mx:Canvas>

NewuserLogin.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="428" styleName="Panelcol" height="408" layout="absolute" borderColor="#6E6F6F">

<mx:Script>
    <![CDATA[
        import mx.core.Application;
       
       
        public function validationtext():void
       
        {
            if(fname.text=="" || lname.text=="" || newpassword.text=="" || newpassword1.text=="")
           
            {
              errormsg.text="Fill the All Fileds";   
            }
            else
            {
               
                errormsg.text="";   
            }
       
        }
       
        public function validationtext1():void
        {
           
           
            if(newpassword.text != newpassword1.text || newpassword.text=="")
           
            {
                errormsg1.text="Please Enter Same Password";
            }
            else
            {
                 
              errormsg1.text="";   
            }
        }
       
        public function cleartextfield():void
       
        {
            fname.text="";
            lname.text="";
            newpassword.text="";
            newpassword1.text="";
        }
       
       
    ]]>
</mx:Script>


    <mx:Label text="Name" x="30" y="53" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="User Name" x="30" y="99" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="Password" x="32" y="150" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="Conform Password" x="30" y="204" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Button x="180" y="273" label="Submit" click="validationtext(),validationtext1(),Application.application.newuser(),cleartextfield();"/>
    <mx:Button x="281" y="273" label="Clear" click="cleartextfield();"/>
    <mx:TextInput x="180" y="54" id="fname"/>
    <mx:TextInput x="180" y="100" id="lname"/>
    <mx:TextInput x="180" y="151" displayAsPassword="true" id="newpassword"/>
    <mx:TextInput x="180" y="203" displayAsPassword="true" id="newpassword1"/>
    <mx:Label x="317" y="8" text="Close Window" fontWeight="bold" useHandCursor="true" buttonMode="true" color="#0C8FAB" textDecoration="underline" click="Application.application.romovepopupnewuser();"/>
    <mx:Label x="9" y="7" text="New User Login" fontWeight="bold" useHandCursor="true" color="#4D6F05" textDecoration="normal" fontSize="14" fontFamily="Arial"/>
    <mx:Label x="176" y="327" width="173" height="20" color="#F43705" id="errormsg"/>
    <mx:Label x="10" y="233" width="173" height="20" color="#F43705" id="errormsg2"/>
    <mx:Label x="177" y="177" width="173" height="20" color="#F43705" id="errormsg1"/>
    <mx:Image source="assets/images/newuser.jpg" width="100" height="96" x="30" y="251"/>
</mx:Panel>


alertpopup.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="272" height="118">
<mx:Script>
    <![CDATA[
            import mx.core.Application;
    ]]>
</mx:Script>
    <mx:Panel width="100%" height="100%" styleName="topspacepanel" layout="absolute">
        <mx:Label text="Do you want to create new user" x="8" y="39" fontWeight="bold"/>
        <mx:Label text="Successfully Created" x="58" y="11" fontWeight="bold" fontSize="12" color="#FC0D0D"/>
        <mx:Button x="55" y="68" label="Yes" click="Application.application.removemsgpopup();" />
        <mx:Button x="140" y="68" label="No" click="Application.application.removeallpopup();" />
       
    </mx:Panel>
</mx:Canvas>


style.CSS

/* CSS file */
.Panelcol {
   borderColor: #6e6f6f;
   borderAlpha: 1;
   borderThicknessLeft: 10;
   borderThicknessTop: 0;
   borderThicknessBottom: 11;
   borderThicknessRight: 10;
   roundedBottomCorners: true;
   cornerRadius: 9;
   headerHeight: 22;
   backgroundAlpha: 1;
   highlightAlphas: 0.5, 0;
   backgroundColor: #ffffff;
   dropShadowEnabled: true;
   shadowDistance: 2;
   shadowDirection: left;
}

.topspacepanel

{
   borderAlpha: 0.59;
   borderThicknessLeft: 5;
   borderThicknessTop: 0;
   borderThicknessBottom: 4;
   borderThicknessRight: 4;
   roundedBottomCorners: false;
   cornerRadius: 0;
   headerHeight: 5;
   backgroundAlpha: 1;
   highlightAlphas: 0.06, 0.19;
   dropShadowEnabled: true;
   shadowDistance: 2;
   shadowDirection: left;


}
Your file keep in this Format



Server Side Files
passoutput.php

<?php
$serv ='localhost';
$usern ='root';
$passw ='';
$databasename = 'flexsample';

$sqlcon = mysql_connect($serv, $usern, $passw) or die(mysql_error());
mysql_select_db($databasename);

$username=mysql_real_escape_string($_POST["usernameres"]);
$password=mysql_real_escape_string($_POST["passwordres"]);

$query = "SELECT * FROM hospitallogin WHERE username = '$username' AND pass = '$password'";
$result = mysql_fetch_array(mysql_query($query));

$output = "<loginsuccess>";

if(!$result)
{
$output .= "no";       
}
else{
$output .= "yes";   
}

$output .= "</loginsuccess>";

//output all the XML
print ($output);
mysql_close($sqlcon);

?>
newusercreate.PHP

<?php
$lhoste='localhost';
$uname='root';
$passval='';
$DatabaseN='flexsample';

$sqlcon = mysql_connect($lhoste, $uname, $passval) or die(msql_error());
mysql_select_db($DatabaseN);

$newusername = mysql_real_escape_string($_POST['newusername']);
$newpasdwod = mysql_real_escape_string($_POST['newuserpass']);

$query = "INSERT INTO hospitallogin VALUES('$newusername','$newpasdwod')";
$result = mysql_fetch_array(mysql_query($query));

$output = "<newuser>";

if(!$result)
{
$output .= "Successfully Created";
}
else{
$output .= "Error";
}

$output .= "</newuser>";
print ($output);
mysql_close($sqlcon);
?>

MYSQL  FORMAT




Output Screen Shots

                                     

                                                                                                                
                                      






Wednesday, March 23, 2011

Upload File From Flex to PHP

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#4E4C4C, #4E4C4C]">
    <mx:Script>
        <![CDATA[
           
            import mx.controls.Alert;
            private var urlRequest:URLRequest;
            private var fileReferenceList:FileReferenceList;
            private var serverSideScript:String = "http://localhost/testfile/uploadFile.php";
           
       
            private function init():void {
           
                fileReferenceList = new FileReferenceList();
                fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);
            }
           
            private function uploadFile():void {
                fileReferenceList.browse();
            }
           
            private function fileSelectedHandler(event:Event):void {
                urlRequest = new URLRequest(serverSideScript);
                var fileReference:FileReference;
                var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
                var fileList:Array = fileReferenceList.fileList;

                // get the first file that the user chose
                fileReference = FileReference(fileList[0]);
               
                // upload the file to the server side script
                fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
                fileReference.upload(urlRequest);
               
                // update the status text
                statusText.text = "Uploading...";
            }
           
            private function uploadCompleteHandler(event:Event):void {
                statusText.text = "File Uploaded: " + event.target.name + event.target.size;
            }

           
        ]]>
    </mx:Script>
   
    <mx:Label text="Upload File From Flex to PHP" fontWeight="bold" color="#FEFFFF" fontSize="23"/>
    <mx:Label text="Choose a file..." id="statusText" color="#FCFDFD" fontSize="17"/>
    <mx:Button click="uploadFile();" label="Upload File"/>
    </mx:Application>


PHP Server Side File

<?php
$url = "D:/uploads/"; //This is Upload file URL
$tempFile = $_FILES['Filedata']['tmp_name'];   // This is going to return the temporary file location
$fileName = $_FILES['Filedata']['name'];  // This is going to return the name.
$fileSize = $_FILES['Filedata']['size'];  // This is going to return the file size in bytes
move_uploaded_file($tempFile, $url.$fileName); //This is going to upload file to your folder
?>

Output







Monday, February 28, 2011

HTML Loder in Flex Air Application

mxml code

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            import mx.events.ResizeEvent;
            import mx.controls.Alert;
       
       private var htm:HTMLLoader=new HTMLLoader();
       private var loc:String = "<html><head></head><body><iframe width='100%' height='100%' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=33 Wood Ave, Iselin, NJ 08246&z=12&output=embed'></iframe></body></html>";
       private var conti:Sprite=new Sprite();
       private var buttun:Boolean=true;
       
        public function aceesslink():void
        {
            htm.loadString(loc);
            conti.addChild(htm);
            uicomponent.addChild(conti);
            /* Alert.show("Hi EveryBody") */;
        }
         
        private function onResize(e:ResizeEvent):void
        {
                htm.width = uicomponent.width;
                htm.height = uicomponent.height;
        }
       
        public function activatebtn():void
        {
              buttun=false;
              if(buttun==false)
              {
                  cheing.selected=false;
                  mapaction.enabled=false;
              }
        }
       
        public function checkboxaction():void
        {
            if(cheing.selected)
            {
                mapaction.enabled=true;
            }
            else
            {
                mapaction.enabled=false;
            }
        }
       
        ]]>
    </mx:Script>
   
   
    <mx:Button x="323" y="535" label="Click ME" id="mapaction" width="146" height="49" click="aceesslink(),activatebtn();"/>
    <mx:Panel x="10" y="10" width="782" height="505" layout="absolute" id="includegoogle">
    <mx:UIComponent  id="uicomponent" width="100%" height="100%" resize="onResize(event)"/>
    </mx:Panel>
    <mx:CheckBox x="16" y="549" label="Map Refresh" id="cheing" selected="true" change="checkboxaction()"/>

</mx:WindowedApplication>

Output Image:


Thursday, September 23, 2010

Dynamically loading data in Data Grid (Flex)

Flex File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" color="#4B5C60" borderColor="#667179" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#5F5E5E, #524D4D]" creationComplete="sendfile.send();">
   
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;
            import mx.collections.XMLListCollection;
            import mx.rpc.events.ResultEvent;
       
        [Bindable]   
        public var datastore:XML;
          [Bindable]
        public var     datacollection:XMLList;
        private var alert:Alert;
        private var coll:Array;

   
    public function retrievedata(event:ResultEvent):void
   
    {
           
     datastore=new XML(event.result);
     datacollection=datastore.datas;
    
     }
        
    private function finderror(event:FaultEvent):void
       
         {
                var title:String = event.type + " (" + event.fault.faultCode + ")";
                var text:String = event.fault.faultString;
                 alert = Alert.show(text, title);
                datacollection.removeAll();
            }
           
 public function checking():void
 {
      Alert.show(datacollection.length());
 }

    public function alertdescription():void
    {
        Alert.show(dataprovider.selectedItem.description);
       
    }
        
        ]]>
    </mx:Script>
   
   
    <mx:HTTPService id="sendfile" url="assets/xmlfile/empdatas.xml" result="retrievedata(event)" resultFormat="e4x"/>

    <mx:DataGrid x="106" y="272" width="682" height="284" id="dataprovider" dataProvider="{datacollection}" change="alertdescription()">
        <mx:columns>

            <mx:DataGridColumn headerText="ID Number" dataField="id" />
            <mx:DataGridColumn headerText="Name" dataField="name"/>
            <mx:DataGridColumn headerText="Designation" dataField="Designation"/>
            <mx:DataGridColumn headerText="Address1" dataField="padress"/>
            <mx:DataGridColumn headerText="Address2" dataField="tadress"/>
           
        </mx:columns>
       
    </mx:DataGrid>
   
    <mx:Button x="106" y="129" label="Data Count" width="100" height="30" click="checking();"/>

   
</mx:Application>


XML File

empdatas.xml

<?xml version="1.0" encoding="utf-8"?>
<overalldata>

<datas>
<id>121</id>
<name>kaniskar</name>
<Designation>Webdesigner</Designation>
<padress>Tuticorin</padress>
<tadress>chennai</tadress>
<description>He is working in chennai. He is a webdesigner</description>
</datas>

<datas>
<id>122</id>
<name>Allwin</name>
<Designation>Marketing</Designation>
<padress>Tuticorin</padress>
<tadress>Chennai</tadress>

<description>He is a Marketing person. Now he is in chennai. </description>
</datas>

<datas>
<id>123</id>
<name>Goodwin</name>
<Designation>Software engineer</Designation>
<padress>Madurai</padress>
<tadress>Bangalore</tadress>
<description>He was engineer in MNC. He is a Senior Developer </description>
</datas>


<datas>
<id>124</id>
<name>Thanabalan</name>
<Designation>Businesman</Designation>
<padress>Tuticorin</padress>
<tadress>Tuticorin</tadress>
<description>He is a big Business man in Kommadikottai. </description>
</datas>

<datas>
<id>125</id>
<name>Raja</name>
<Designation>Software</Designation>
<padress>Chennai</padress>
<tadress>Bangalore</tadress>
<description>He was engineer in MNC. He is a Senior Developer </description>
</datas>

<datas>
<id>126</id>
<name>Arasu</name>
<Designation>PHP Developer</Designation>
<padress>Madurai</padress>
<tadress>Meenakshi Temple Street</tadress>
<description>He is working as a PHP Developer. Now He is working in  madurai</description>
</datas>

<datas>
<id>127</id>
<name>Boopathi</name>
<Designation>Teacher</Designation>
<padress>Rameshwaram</padress>
<tadress>Temple Street,</tadress>
<description>Now he is in chennai. He is searching another job </description>
</datas>

</overalldata>

 Your file keep in this format










Output