private var _myObjArr:Array = new Array(); // array of objects
private var _stringAuthor:String;
private var _stringDate:String;
private var _stringText:String;
/**
* Success handler after requesting JSON data from server
*
* @param event Event
* @return void
*/
private function onSuccess(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
var data:Object = null;
try { // get the raw JSON data
data = JSON.decode(loader.data);
} catch(e:Error) {
trace("Error requesting document");
}
loader.close();
loader = null;
if (data !=null)
{
if (data.error)
{
trace(data.error);
} else {
// loop thru data
for (var key:Object in data) {
_stringAuthor = '<p><span class="author">' + data[key].author + '</span></p>';
_stringDate = '<span class="date">' + data[key].date + '</span></p>';
_stringText = '<p><span class="text"> "' + data[key].text + '"</span></p>';
// save Author, Date, Text to an object array _myObjArr
var obj:Object = new Object();
obj.Author = _stringAuthor;
obj.Date = _stringDate;
obj.Text = _stringText;
_myObjArr.push(obj);
}
}
}
} // end onSuccess
// now that we got all our info saved, we can retrieve it later in other functions like:
for(var i:uint = 0; i < _myObjArr.length; i++) {
_blogPost[i] = addBlogPosts();
addChild(_blogPost[i]);
}
// does this snippet help anyone?