package {
import com.adobe.serialization.json.JSON;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TextEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.StyleSheet;
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=16"));
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();
var oStyle:StyleSheet = new StyleSheet();
var oA:Object = {color: "#0B7ECE"};
oStyle.setStyle("a", oA);
oFmt.size = 14;
oText.htmlText = (arr[i].text||arr[i].link_title||arr[i].link_desc).replace(/@(.+?)(?=\s)/g, "@<a class='a' href='event:http://rensea.com/$1'>$1</a>");
oText.setTextFormat(oFmt);
oText.styleSheet = oStyle;
if(oTemp && oTemp.height) oText.y = oTemp.y + oTemp.height;
trace(oText.y);
addChild(oText);
oText.addEventListener(TextEvent.LINK, clickLink);
oTemp = oText;
}
}
private function clickLink(event:TextEvent):void{
var oRq:URLRequest = new URLRequest(event.text);
navigateToURL(oRq, "_blank");
}
}
}
posted on 2009-09-17 00:42
汪杰 阅读(236)
评论(0) 编辑 收藏 引用 所属分类:
as3