Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This example sets up an asynchronous process that will complete with a
- * complete signal
- */
- public class Example
- {
- private var _complete:Signal;
- public function Example()
- {
- _complete = new Signal(Example);
- }
- public function start():void
- {
- t = new Timer(50, 1);
- t.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
- t.start();
- }
- private function onTimerComplete(event:TimerEvent):void
- {
- onComplete();
- }
- /**
- * when complete, I really, really don't want any previous listeners that were added
- * instead of addOnced to be around so I'm going to add a layer of precaution by removing
- * all my listeners after dispatch
- */
- protected function onComplete():void
- {
- _complete.dispatch(this);
- _complete.removeAll(); // this line clearly breaks the use-case below, but I need it
- }
- public function get complete():ISignal
- {
- return _complete;
- }
- }
- /**
- * This class will construct the example, listen for the onComplete and start again. The problem is that
- * the second time the onComplete will never be hit.
- */
- public class Use
- {
- private var _example:Example;
- public function Use()
- {
- _example = new Example();
- _example.complete.addOnce(onComplete);
- _example.start();
- }
- private function onComplete(example:Example):void
- {
- trace("tada!");
- _example.complete.addOnce(onComplete);
- _example.start();
- }
- }
Add Comment
Please, Sign In to add comment