[Flashcoders] AS3: Static functions and events ...

2008-05-22 Thread Stephen Ford
Is there anyway for a static function within a class to fire off an event? 
assuming the static function exists within a class that has no constructor (ie: 
is never instantiated).

As I understand it, for another object to  be listening for the event, said 
object must have a local refence to the class doing the dispatching?

Anyway around this.

SF.


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


Re: [Flashcoders] AS3: Static functions and events ...

2008-05-22 Thread jonathan howe
I just ran into this the other day, and I created a public static variable
in the class called instance. When the static class is initialized via
some sort of init() function, I create a sole, empty instance of the class
whose only role is to dispatch events. Thus, when I have to assign a
listener, I assign it to the instance, for example:

public static var instance:SingletonClass
...
public function SingletonClass() {

}
...
public static function init():void {
instance = new SingletonClass();
}

then,  to add event listener
SingletonClass.instance.addEventListener(SingletonClass.EVENT_NAME,
listenerFunction);

I'd love to hear about drawbacks to this approach. I'm sure there are some
issues, and this was a new problem/idea.

-jonathan

On Thu, May 22, 2008 at 12:16 PM, Stephen Ford [EMAIL PROTECTED] wrote:

 Is there anyway for a static function within a class to fire off an event?
 assuming the static function exists within a class that has no constructor
 (ie: is never instantiated).

 As I understand it, for another object to  be listening for the event, said
 object must have a local refence to the class doing the dispatching?

 Anyway around this.

 SF.


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




-- 
-jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] AS3: Static functions and events ...

2008-05-22 Thread Matheus Henrique Gorino
Grant Skinner has created a nice solution for it:
http://www.gskinner.com/blog/archives/2007/07/building_a_stat_1.html


On Thu, May 22, 2008 at 1:56 PM, jonathan howe [EMAIL PROTECTED] wrote:
 I just ran into this the other day, and I created a public static variable
 in the class called instance. When the static class is initialized via
 some sort of init() function, I create a sole, empty instance of the class
 whose only role is to dispatch events. Thus, when I have to assign a
 listener, I assign it to the instance, for example:

 public static var instance:SingletonClass
 ...
 public function SingletonClass() {

 }
 ...
 public static function init():void {
instance = new SingletonClass();
 }

 then,  to add event listener
 SingletonClass.instance.addEventListener(SingletonClass.EVENT_NAME,
 listenerFunction);

 I'd love to hear about drawbacks to this approach. I'm sure there are some
 issues, and this was a new problem/idea.

 -jonathan

 On Thu, May 22, 2008 at 12:16 PM, Stephen Ford [EMAIL PROTECTED] wrote:

 Is there anyway for a static function within a class to fire off an event?
 assuming the static function exists within a class that has no constructor
 (ie: is never instantiated).

 As I understand it, for another object to  be listening for the event, said
 object must have a local refence to the class doing the dispatching?

 Anyway around this.

 SF.


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




 --
 -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

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