forked from: Singleton
forked from Singleton (diff: 21)
ActionScript3 source code
/**
* Copyright mi77 ( http://wonderfl.net/user/mi77 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aSkQ
*/
// forked from kamipoo's Singleton
package {
import flash.display.Sprite;
import flash.text.*;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var singleton:Singleton = Singleton.getInstance();
// 本当にSingletonになってるかな
////////////////////////////////////////////////////////////
var singleton2:Singleton = Singleton.getInstance();
var tf = addChild(new TextField())
tf.width=500;
tf.text = String(singleton);
tf.appendText("\n"+String(singleton2));
tf.appendText("\n\nあれれ? これだと何個でもつくれちゃう?");
tf.appendText("\n\nいや。それでいいのだ。");
////////////////////////////////////////////////////////////
}
}
}
class Singleton {
private static var _INTERNAL_CALL:Boolean = false;
private static var _INSTANCE:Singleton;
public function Singleton() {
if(!_INTERNAL_CALL) {
new ArgumentError("error");
}
}
public static function getInstance():Singleton {
if(!_INSTANCE) {
_INTERNAL_CALL = true;
_INSTANCE = new Singleton();
_INTERNAL_CALL = false;
}
return _INSTANCE;
}
}
