第一次海報在這裏。AS3公共變量不會存儲值
所以我建立一個「多RSS閱讀器」和我分成2班,「TechFeed.as」和「Feed.as」這一點;技術提要通過將URL傳遞給新的Feed對象來實例化多個提要。
我現在的問題是,在Feed.as中,我有一對公共變量,它們在TechFeed.as中用於顯示有關Feed的基本細節,但是,這些變量拒絕保留我給它們的任何值Feed.as的功能,並打開「空」。
編輯:也可能要注意; TechFeed.as是舞臺使用的主要AS文件。
TechFeed.as
package {
import flash.display.MovieClip;
public class TechFeed extends MovieClip {
private var feed_one:Feed = new Feed("http://feeds.feedburner.com/crunchgear");
private var feed_two:Feed = new Feed("http://feeds.mashable.com/Mashable");
private var feed_three:Feed = new Feed("http://www.engadget.com/rss.xml");
public function TechFeed() {
trace(feed_one.feed_title);
//feed_name.text = feed_one.getFeedTitle();
}
}
}
Feed.as
package {
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
public class Feed {
//Public variables to display feed info
public var feed_title:XMLList;
public var feed_desc:String;
public var feed_link:String;
//Setting up variables which help load the feeds
private var feedXML:XML;
//Create a loader to load an external URL
private var loader:URLLoader = new URLLoader();
public function Feed(inURL:String = "") {
//Load the xml document
loader.load(new URLRequest(inURL));
loader.addEventListener(Event.COMPLETE,onLoaded);
}
//When the loader had loaded the xml document, pass that into a variable for use.
private function onLoaded(e:Event):void {
feedXML = new XML(e.target.data);
// break down the xml document elements into singular XML array lists
//Feed details
this.feed_title = feedXML.channel.title;
this.feed_link = feedXML.channel.link;
this.feed_desc = feedXML.channel.description;
trace(this.feed_title);
}
}
}
任何幫助,將不勝感激:)
感謝, 傑夫
加載是異步操作,所以你必須要等到XML被加載,比讀「FEED_TITLE」價值 – turbosqel
@turbosqel我怎麼知道什麼時候完成?我不知道應該在dispatchEvent中放入什麼答案... – Geoff