topical media & game development

talk show tell print

lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup.ax

lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup.ax (swf ) [ flash ] flex


  package org.as3lib.kitchensync.action
{
        import flash.utils.getQualifiedClassName;
        
        import org.as3lib.kitchensync.core.*;
        
        
* A group of actions that executes all at once the group is started and the delay is reached.

  
        public class @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup extends AbstractActionGroup
        {        
                
                protected var _runningChildren:int = 0;
                
                public  function get childrenAreRunning():Boolean { return _runningChildren > 0; }
                
                
* Constructor. * * @throws TypeError - if any children are not of type AbstractSynchronizedAction. * * @params children - a list of AbstractSynchronizedActions that will be added as children of the group.

  
                public function @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup (... children) {
                        super();
                        for (var i:int = 0; i < children.length; i++) {
                                if (children[i] is IAction) {
                                        var action:IAction = IAction(children[i]);
                                        addAction(action); 
                                } else {
                                        throw new TypeError ("All children must be of type IAction. Make sure you are not calling start() on the objects you've added to the group. Found " + getQualifiedClassName(children[i]) + " where IAction was expected.");
                                }
                        }
                }
                
                
* When the first update occurs, all of the child actions are started simultaniously.

  
                override public function update(currentTimestamp:Timestamp):void {
                        if (startTimeHasElapsed && !childrenAreRunning) {
                                // reset the number of running children.
                                _runningChildren = 0;                                
                                // for all child actions
                                for (var i:int=0; i < _childActions.length; i++) {
                                        var childAction:IAction = IAction(_childActions[i]);
                                        // add a listener to each action so that the completion of the entire group can be tracked.
                                        childAction.addEventListener(KitchenSyncEvent.START, onChildStart);
                                        childAction.addEventListener(KitchenSyncEvent.COMPLETE, onChildFinished);
                                        // start the child action
                                        childAction.start();
                                        // add one running child.
                                        _runningChildren++;
                                }
                                // once this has started, it doesn't need updates anymore.
                                unregister();
                        }
                }
                
                
                
* Called when child actions are completed. After each is finished, checks to see if the entire set is * complete. If not, it waits for the next child. * Completed children are removed from the array so they can be garbage collected. * *
parameter: event - The SynchronizerEvent.COMPLETE * @param event - The SynchronizerEvent.CHILD_COMPLETE */ override protected function onChildFinished (event:KitchenSyncEvent):void { super.onChildFinished(event); var childAction:IAction = IAction(event.target); childAction.removeEventListener(KitchenSyncEvent.COMPLETE, onChildFinished); childAction.removeEventListener(KitchenSyncEvent.START, onChildStart); _runningChildren--; if (_runningChildren == 0) { complete(); } } override public function stop():void { super.stop(); _runningChildren = 0; } override public function clone():IAction { var clone:@ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup = new @ax-lib-flex-animation-code-10-org-as3lib-kitchensync-action-KSParallelGroup(); for (var i:int = 0; i < _childActions.length; i++) { var action:IAction = getChildAtIndex(i).clone(); clone.addActionAtIndex(action, i); } clone.delay = _delay; clone.autoDelete = _autoDelete; return clone; } override public function toString():String { return "Parallel group containing " + _childActions.length + " children"; } }}

(C) Æliens 19/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-2780434-1"; urchinTracker(); </script>