package {
import com.adobe.serialization.json.JSON;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
[SWF(width="350",height="500")]
public class JSONTest extends Sprite
{
public function JSONTest()
{
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("http://rensea.com/statuses/user_timeline/asfman.json?count=20"));
loader.addEventListener(Event.COMPLETE, decodeJSON);
}
private function decodeJSON(event:Event):void{
var oRenseaArr:Array = JSON.decode(event.target.data);
renseaApiParser(oRenseaArr);
}
private function renseaApiParser(arr:Array):void{
var oTemp:TextField;
for(var i:uint = 0, l:uint = arr.length; i < l; i++){
var oText:TextField = new TextField();
oText.autoSize = "left";
oText.wordWrap = true;
oText.multiline = true;
oText.width = 350;
var oFmt:TextFormat = new TextFormat();
oFmt.size = 12;
oText.appendText(arr[i].text||arr[i].link_title||arr[i].link_desc);
oText.setTextFormat(oFmt);
if(oTemp && oTemp.height) oText.y = oTemp.y + oTemp.height;
trace(oText.y);
addChild(oText);
oTemp = oText;
}
}
}
}
posted on 2009-09-17 00:15
汪杰 阅读(241)
评论(0) 编辑 收藏 引用 所属分类:
flash