asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
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 汪杰 阅读(221) 评论(0)  编辑 收藏 引用 所属分类: as3
只有注册用户登录后才能发表评论。

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457560
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜