0 Replies Latest reply on May 22, 2012 5:04 AM by skant

    Read variable from class - not working

    skant Level 1

      Hello,

       

       

      I'm trying to read a variable from a external class to my xmml source,

       

      This class reads an XML. When data is loaded the class launches an event,

      (I simplified with only one variable sample)

       

      package skant
      {
        
      import flash.net.URLRequest;
        
      import flash.net.URLLoader;
        
      import flash.events.Event;
        
      import flash.display.MovieClip;
        
        
      public class XmlData extends MovieClip
           
        
      {
           
      public var liveId:URLRequest = new URLRequest ("file.xml");
           
      public var xmlLoader:URLLoader = new URLLoader;
           
           
      public var liveID:int = new int;
         
           
      public function cargarDatos(event:Event):void 
           
      {
               xmlLoader
      .addEventListener (Event.COMPLETE, datosCargados);
               xmlLoader
      .load (liveId);
           
      }


           
      public function datosCargados (event:Event):void {
                 
                 
      var articulosXML:XML = XML (event.target.data);
                 
                  liveID
      = articulosXML.live;

              
                  trace
      ("external: "+liveID);
                 dispatchEvent
      (event);
                 
           
      }  
        
      }}

       

       

      Trace and dispatchEvent work fine

       

      in mxml file,

      I had a listener who is waiting for the event,

       

               public function xmlListener (event:Event):void {
              
                 
      var miXML2:XmlData = new XmlData;
                  miXML2
      .cargarDatos(event);
                  miXML2
      .addEventListener (Event.COMPLETE, Charge);
                  trace
      ("xmlListener ok");         
              
              
      }

      That works fine,

       

      the problem is with the next function, Charge,

       

      public function Charge (event:Event):void {
                 
                 
      var liveID:int;
             
                 
      var miXML:XmlData = new XmlData;
                  miXML
      .cargarDatos(event);
                  trace
      ("interno: "+liveID);

      }

       

      The variable liveID is not working is 0 and hds to be 1.

      Any idea?

      Why is not working?

       

      thanks,

      best regards,

      Skant