[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1319
  • Last Modified:

Converting the return values of URL Loader into an array in Actionscript 3

I am taking values from an Access database into an ASP file and from there into Flash.
I am getting the data ok, but however I am having problembs converting that data from the loader object into an Array.

These are the values I am getting in Flash from ASP. What is the best way to convert this into an array?

completeHandler: 1/2/2007,56.036,56.2,55.94;01/3/2007,56.023,56.197,55.94;01/1/2008,18.847,0,0;02/1/2008,18.86,0,0;03/1/2008,18.845,0,0;04/1/2008,18.842,0,0;05/1/2008,18.848,0,0;06/1/2008,18.856,0,0;07/1/2008,18.855,0,0;08/1/2008,18.855,0,0;0

 If anyone can helpe me out, it will be greatly appreciated.
Best,
TMC

ASP CODE Snippet:
Do While not rsLakes.EOF

      Response.Write (rsLakes("SDate"))
      Response.Write (",")      
      Response.Write (rsLakes("DailyL"))
      Response.Write (",")      
      Response.Write (rsLakes("High"))
      Response.Write (",")      
      Response.Write (rsLakes("Low"))
      Response.Write (";")      
      Response.Write (rsLakes("Curve"))
      Response.Write (" ; ")      

      'Move to the next record in the recordset
      rsLakes.MoveNext

Loop



function lakes(){
	
	var loader:URLLoader = new URLLoader();
var nrequest:URLRequest = new URLRequest("lakes.asp");
 
var variables:URLVariables = new URLVariables();
variables.LNumber = glo.bal.lakeNumber;
nrequest.data = variables;
nrequest.method = "POST"; // !! this is the default 
loader.load(nrequest);
configureListeners(loader);
	trace(nrequest.data);
 
}
  
 
 
 
        function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
 
		function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
 trace("completeHandler: " + loader.data);}
			           
 
        function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }
 
       function progressHandler(event:ProgressEvent):void {
            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
        }
 
        function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
 
        function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
 
        function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
 
 
lakes();

Open in new window

0
TheMagellanClouds
Asked:
TheMagellanClouds
  • 2
1 Solution
 
julianopolitoCommented:
i'll send you an example in a minute
0
 
julianopolitoCommented:
Here it goes. If you have any doubts let me know
function completeHandler(event:Event):void {
      var loader:URLLoader = URLLoader(event.target);
      trace("completeHandler: " + loader.data); 
      //now let's convert it to an array
      var splitRows:Array = loader.data.split(";");//returns array from string, breaking items by delimiter ";"
      var rows:Array = [];//the final array
      for(var i = 0; i < splitRows.length;i++){
           rows.push(splitRows[i].split(","))
       }
       //here you can access the bidimensional array like this
      trace(rows[0][2]);//traces 56.2, 3rd field in 1st row
      
}

Open in new window

0
 
TheMagellanCloudsAuthor Commented:
Thanks a lot man that worked like a charm!
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now