actionscript3不能用private修饰构造方法,因此可以用一个内部类来做构造方法的参数:

 

代码
1 package DesignPatterns
2 {
3 import mx.controls.Alert;
4 public class Singleton
5 {
6 private static var singleton:Singleton;
7 public function Singleton(privateclass:privateClass)
8 {
9 Alert.show("this is pulic Class");
10 }
11
12 public static function getInstance():Singleton{
13 if(singleton==null){
14 singleton = new Singleton(new privateClass());
15 }
16 return singleton;
17 }
18
19 }
20 }
21
22 import mx.controls.Alert;
23 class privateClass{
24 public function privateClass(){
25 Alert.show("this is private Class");
26 }
27 }
posted on 2010-01-16 14:39  热夜之梦  阅读(1806)  评论(0编辑  收藏  举报