class NewsFeed
{
/*下面的三个方法在AS2.0中在使用前还必须要进行声明,(感谢blueidea中坛友noahgenius
的提醒)不然无法使用,在AS1.0中不需要,实在是不理解MM要多此一举*/
var addListener : Function;
var removeListener : Function;
var broadcastMessage : Function;
var name : String;
function NewsFeed (name)
{
this.name = name;
AsBroadcaster.initialize (this);
addListener (this);
}
function toString () : String
{
return this.name;
}
function sendNews (headline : String, summary : String, url : String) : Void
{
broadcastMessage ("onNews", this, headline, summary, url);
}
natPress = new NewsFeed ("National Press");
NABC = new Object();
AICN = new Object();
NABC.onNews = function (source, headline, summary, url) {
trace ("----- NABC News -----");
trace (">" + headline + "<");
trace (summary);
trace (">>" + url);
trace ("[via" + source +"]");
trace ("--");
};
AICN.onNews = function (source, headline, summary, url) {
trace ("///// Ain't It Crazy News /////");
trace ("Unbelievable!!");
trace (headline + "!!!");
trace (source + " reports: '" + summary + "'");
trace ("Read the rest of the incredible story here:");
trace (url);
trace ("//");
};
natPress.addListener (NABC);
natPress.addListener (AICN);
trace (natPress._listeners); // output: [object Object],[object Object]
natPress.sendNews ( "Marcosoft buys Murkimedia",
"After months of secret negotiations, Marcosoft absorbs its chief rival",
"http://www.marcosoft.com" )
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。