你什麼'尋找是這樣的:
import fl.controls.TextArea;
/**** vars ****/
var user:String;
var url:String;
var tweetCount:int;
var tweets:Array;
var times:Array;
var textArea:TextArea;
/**** setup ****/
user = "leifpagrotsky";
tweetCount = 10;
setupText();//setup a text area component
loadTweets();
/**** start getting tweets ****/
function loadTweets()
{
url = "http://search.twitter.com/search.atom?q=+from:" + user + "&rpp=" + tweetCount;
var urlReq:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, getTweets);
loader.addEventListener(IOErrorEvent.IO_ERROR, IOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, SError);
loader.load(urlReq);
}
function setupText():void{
textArea = addChild(new TextArea()) as TextArea;//create and add it to the stage - make sure the component is in the library
textArea.setSize(stage.stageWidth,stage.stageHeight);
textArea.editable = false;
}
function getTweets(e:Event):void
{
if (e.target.data)
{
var displayText:String = "";//make a string to collect all the text you want to display
tweets = new Array();
times = new Array();
var twitterXML:XML = new XML(e.target.data);
var tweetList:XMLList = twitterXML.children();
var tweetItem:String;
var timeItem:String;
for (var i:int = 0; i < tweetList.length(); i++)
{
tweetItem = tweetList[i].*::title;
timeItem = tweetList[i].*::published;
if (tweetItem != "")
{
tweets.push(tweetItem);
trace(tweetItem);
displayText += tweetItem+"\n";//add the details you need like the message
}
if (timeItem != "")
{
timeItem = timeItem.split("T").join(" - ");
timeItem = timeItem.split("Z").join("");
times.push(timeItem);
trace(timeItem);
displayText += timeItem+"\n\n";//...and time
}
}
trace(tweets.length);
textArea.text = displayText;//finally after all the text is accumulated into a string, send it to the text area
}
}
function IOError(e:Event):void
{
trace("io error!");
}
function SError(e:Event):void
{
trace("security error!");
}
我在使用教程時建議將他們區分開來並理解每一部分。那麼應該明白需要做什麼。只是複製/粘貼代碼而不理解它是不夠的。
使用基本的TextField也可以。這裏有一個簡化版本:
var output:TextField = addChild(setupText()) as TextField;//add text
loadTweets("leifpagrotsky",10);//call tweeter
function loadTweets(user:String,count:int):void{
new URLLoader(new URLRequest("http://search.twitter.com/search.atom?q=+from:" + user + "&rpp=" + count))
.addEventListener(Event.COMPLETE,tweetsLoaded);//load and wait for the response
}
function tweetsLoaded(e:Event):void{
if(e.target.data){//if we have some data
var out:String = "";//make a new blank string we can later plug into the text on screen
var stream:XML = new XML(e.target.data);//plug the data into an XML object
var tweets:XMLList = stream.*;//get the tweet nodes
var numTweets:int = tweets.length();//count them once
for(var i:int = 0 ; i < numTweets; i++) //for each tweet message
if(String(tweets[i].*::title).length) //if there the message's length is > 0
out += tweets[i].*::title+"\n<b>"+tweets[i].*::published+"</b>\n\n";//add it to our string
output.htmlText = out;//finally plug the string to the text field
}
}
function setupText():TextField {//set up the text field
var t:TextField = new TextField();
t.defaultTextFormat = new TextFormat("Verdana",11,0);
t.multiline = true;
t.autoSize = TextFieldAutoSize.LEFT;
t.width = stage.stageWidth;
t.height = stage.stageHeight;
t.border = true;
return t;
}
「似乎無法使TextArea和Actions-code連接。」你有什麼嘗試? – 2013-03-26 08:58:41
@JonatanHedborg 我把這段代碼扔掉了,我不記得它。但是,問題在於,我需要將Actions和TextArea連接起來嗎? – user1390252 2013-03-26 10:54:25
像'yourTextAreaInstance.text =「您的消息」;'? – 2013-03-26 11:22:55