Revision: 24072
Updated Code
at February 20, 2010 04:31 by abbey
Updated Code
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?
Revision: 24071
Updated Code
at February 20, 2010 04:30 by abbey
Updated Code
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?
Revision: 24070
Updated Code
at February 20, 2010 04:29 by abbey
Updated Code
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?
Revision: 24069
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 20, 2010 04:28 by abbey
Initial Code
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(_commentBlock[index]); } // does this snippet help anyone?
Initial URL
Initial Description
Notes to self: re-use this for other projects
Initial Title
AS3: Creating an array of objects for storing JSON data
Initial Tags
object, actionscript, array, flash, json, Flex
Initial Language
ActionScript 3