Hi,
I built a class that parses JSON data, stores it in an array, and now I want to return that data so that it can be stores in an array in my root AS file. I'm eventually trying to pass the returned array to another class. My class looks like this:
package com.src
{
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import com.src.serialization.json.JSON;
public class DataGrab extends Sprite
{
public var jsonData:Object;
public function DataGrab()
{
}
public function init(resource:String):void
{
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(resource);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(request);
}
private function onComplete(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
jsonData = JSON.decode(loader.data);
}
public function getResults():Array
{
var people = jsonData.people;
var names:Array = people.name;
var payload = new Array();
var counter:Number = 0;
for (var key:Object in names)
{
payload[counter] = [names[key].id, names[key].email];
counter++;
}
return payload;
}
}
}
When I call the class in the root AS file, my code looks like:
var grabData:DataGrab = new DataGrab();
grabData.init(url:String);
var resultData:Array = grabData.payload();
I keep getting the following error however:
1061: Call to a possibly undefined method payload through a reference with static type com.src.DataGrab.
Does anyone have advice on what might be wrong with my class, or a more logical way to write the getResults() function so that I can get retrieve the array being generated by this class?
Thanks.