<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
import mx.containers.TitleWindow;
import flash.net.navigateToURL;
import mx.core.Repeater;
import mx.controls.Text;
import mx.containers.Panel;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import com.adobe.serialization.json.JSON
private function init():void{
var userName:String = parameters.userName|| "asfman";
var showNum:uint = parameters.showNum || 10;
var oText:Text;
var oPanel:Panel = new Panel();
var ld:URLLoader = new URLLoader();
var oUrlRq:URLRequest = new URLRequest("http://rensea.com/statuses/user_timeline/" + userName + ".json?count="+ showNum);
ld.addEventListener(Event.COMPLETE, function(evt:Event):void{
var arrData:Array = JSON.decode(evt.target.data);
oPanel.title = userName + "的最近更新";
oPanel.styleName = "panel";
oPanel.width = parameters.width ? parameters.width : 350;
if(parameters.height)oPanel.height = parameters.height;
addChild(oPanel);
arrData.forEach(arrHandler);
});
ld.load(oUrlRq);
function arrHandler(oItem:Object, index:int, arr:Array):void{
oText = new Text();
oText.htmlText = (oItem.text||oItem.link_title||oItem.link_desc).replace(/@(.+?)(?=\s)/g, "@<a class='link' href='event:http://rensea.com/$1'>$1</a>");;
if(index == 0){
oText.styleName = "first";
}else if(index == arr.length -1){
oText.styleName = "last";
}else{
oText.styleName = "text";
}
oText.width = oPanel.width - 40;
oText.addEventListener(TextEvent.LINK, clickLink);
oPanel.addChild(oText);
}
}
private function clickLink(event:TextEvent):void{
var oRq:URLRequest = new URLRequest(event.text);
navigateToURL(oRq, "_blank");
}
]]>
</mx:Script>
<mx:Style>
.panel{font-size: 14px;}
.link{color: #0B7ECE;}
.first{padding-left: 8px; padding-right: 8px; padding-top: 8px;}
.last{padding-left: 8px; padding-right: 8px; padding-bottom: 8px;}
.text{padding-left: 8px; padding-right: 8px;}
</mx:Style>
</mx:Application>
posted on 2009-09-18 13:36
汪杰 阅读(164)
评论(0) 编辑 收藏 引用