5 Replies Latest reply on Aug 21, 2009 6:55 AM by Fabien Warniez

    Arrays in Eventhandling function

    subba99

      Hi

      I just created one flex application using <mx:http>  tag with resultHandler event  function

       

      <mx:HTTPService id="employees" url =" c:/sai/one.xml" result="resultHandler(event)"  fault="httpFaultHandler(event)"
      resultFormat="e4x"
      />

       

       

      private function resultHandler(event:ResultEvent):void
        {
         var  custresultdata:XMLList=new XMLList();
         var labelsArray:Array /* of String */ = new Array(custresultdata.length);
                var index : int = 0;
                var i:int=0;
                custresultdata=event.result.customer; 
         for each (var labelText:String in custresultdata)
                        {
                               labelsArray[index++] = labelText;
                          }
                          aa=labelsArray;

      i=aa.length;

      Alert.show(p.toString());/       *here it  showing the length is 5 */

                          }

       

       

      my problem is the function returning data to array named as aa,but  when i try to assigning the same array aa to another array hh out side of this function,the array hh is not contaning data

       

      public function init():void
        {
        
         employees.send();
         hh=aa;
         p=hh.length;
         Alert.show(p.toString());  /*here it  showing the length is 0 */
        
        }

      here i am posting the entire code of my application,

      how can i slove this problem

      thanks in advance

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
      initialize="init()">
      <mx:Script>
      <![CDATA[
        import mx.collections.XMLListCollection;
        import mx.controls.dataGridClasses.DataGridColumn;
        
        
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.controls.Alert;
      [Bindable]
      public var aa:Array = new Array();
      public var hh:Array=new Array();
      public var p:int=0;
       
         [Bindable]
        private var empdata:XMLListCollection=new XMLListCollection;
        public function init():void
        {
        
         employees.send();
         hh=aa;
         p=hh.length;
         Alert.show(p.toString());
        
        }
        private function resultHandler(event:ResultEvent):void
        {
         var  custresultdata:XMLList=new XMLList();
         var labelsArray:Array /* of String */ = new Array(custresultdata.length);
                var index : int = 0;
                var i:int=0;
                custresultdata=event.result.customer; 
         for each (var labelText:String in custresultdata)
                        {
                               labelsArray[index++] = labelText;
                          }
                          aa=labelsArray;
                          }
         private function httpFaultHandler(event:FaultEvent):void
         {
          Alert.show("there was a prolem");
         
         }
          ]]>
      </mx:Script>
      <mx:HTTPService id="employees" url =" c:/sai/one.xml" result="resultHandler(event)"  fault="httpFaultHandler(event)"
      resultFormat="e4x"
      />

       
           
      </mx:WindowedApplication>