There is no such thing as calling a constant. And static properties are
only initialized once.

Your approach only serves to delay the construction of the instance to
the moment it is first accessed, as opposed to when the runtime decides
to initialize the constant.

What OP needs is a singleton that can be destructed. The problem here is
that the constant that is holding a reference to the instance never
leaves scope and can't be changed not to point at the instance.

The way I would do it would be to either fix the scheduler to correctly
terminate the flash player or to reuse the flash player instead of
spawning a new one each time.

In fact, I doubt that OP actually means "flash player", but rather means
"a random swf file that I load every so often". That would be a prime
example of where reuse is the correct approach.

Peter Ginneberge skriver:
> That's not a singleton, as every time you call the public static
> constant, it creates a new instance.
> 
> The static var should be private and the class needs an access point
> method, usually called getInstance();
> 
>  private static var INSTANCE:AppApi;
> 
>  public function AppApi():void {
>   if (INSTANCE != null ) {
>    throw new Error("Only one instance allowed. " +
>     "To access the Singleton instance, use getInstance().");   }
>  }
>  
>  public static function getInstance():AppApi{
>   if(!INSTANCE) INSTANCE = new AppApi();
>   return INSTANCE;
>  }
>  
> 
> Then elsewhere in your app you refer to the singleton with:
> AppApi.getInstance();
> 
> 

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to