[code="java"]package tristanbf.cauc.events
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
public class GlobalDispacher extends EventDispatcher
{
private static var instance:GlobalDispacher;
public function GlobalDispacher(target:IEventDispatcher=null)
{
if(instance == null)
{
instance = this;
}
}
public static function getInstance():GlobalDispacher
{
if(instance == null)
{
instance = new GlobalDispacher();
}
return instance;
}
}
}
[/code]
Flex actionscript3.0 求大神讲解
一个单例模式。
这个GlobalDispacher对象只能被创建一个。
不知道as的构造函数能不能写成private,这里的是public,所以在构造函数返回的是当前对象。
使用就是GlobalDispacher.getInstance() 得到 GlobalDispacher的实例对象instance
flex的构造函数不能私有