📄 sequencebase.as
字号:
/** * Pauses sequence play. * * @return Returns true unless sequence was unable to pause any children. */ public function pause() : Boolean { var prevState:String = _state; if (_state==STOPPED || _state==PAUSED) return false; _state = PAUSED; if (_getCurrentStep().pause()==false) { _state = prevState; return false; } dispatchEvent(new GoEvent( GoEvent.PAUSE )); return true; } /** * Resumes previously-paused sequence play. * * @return Returns true unless sequence was unable to resume any children. */ public function resume() : Boolean { if (_state != PAUSED || _getCurrentStep().resume()==false) { return false; } _state = PLAYING; dispatchEvent(new GoEvent( GoEvent.RESUME)); return true; } /** * Stops the current step and skips to another step by sequence index. * * @return Always returns true since the index is normalized to the sequence. */ public function skipTo(index : Number) : Boolean { _state = PLAYING; var prevIndex:int = _index; _index = _repeater.skipTo(_steps.length-1, index); if (_index==prevIndex) { (_getCurrentStep() as IPlayable).skipTo(0); } else { _steps[prevIndex].stop(); // _index is updated before this call so that onStepEvent ignores the item's STOP event. _getCurrentStep().start(); } return true; } // -== Add hooks for these methods to your subclass like Sequence & SequenceCA ==- // These methods are broken out to allow subclasses to use exact typing for their SequenceStep class. /** * Developers: Add a getter called <code>currentStep</code> to your subclass as in Sequence. * * @return Developers: return the correct SequenceStep type for your subclass in your corresponding public method. */ protected function _getCurrentStep() : * { return (_steps.length==0 ? null : _steps[_index]); } /** * Developers: Add a getter called <code>lastStep</code> to your subclass as in Sequence. * * @return Developers: return the correct SequenceStep type for your subclass in your corresponding public method. */ protected function _getLastStep() : * { return (_steps.length==0 ? null : _steps[ _steps.length-1 ]); } /** * Developers: Add a method called <code>getStepAt</code> to your subclass as in Sequence. * * @param index An array index starting at 0. * @return Developers: return the correct SequenceStep type for your subclass in your corresponding public method. */ protected function _getStepAt(index:int) : * { if (index >= _steps.length) return null; return (_steps[index] as SequenceStep); } /** * Developers: Add a method called <code>getStepByID</code> to your subclass as in Sequence. * * @param playableID The step instance's playableID to search for. * @return Developers: return the correct SequenceStep type for your subclass in your corresponding public method. */ protected function _getStepByID(playableID:*) : * { for each (var step:SequenceStep in _steps) if (step.playableID===playableID) return step; return null; } /** * Developers: Add a method called <code>addStep</code> to your subclass as in Sequence. * * <p>Drop the third parameter in your subclass' addStep method. Use it to be sure * the correct type of wrapper is created, as in SequenceCA.</p> * * @param item The playable item to add to the sequence. * * @param addToLastStep If true is passed the item is added to the last * existing SequenceStep in the steps array. This * option should be used with individual items that * you want added as children to the SequenceStep. * If there are no steps yet this option ignored and * a new step is created. * * @param stepTypeAsClass Type for SequenceSteps. (Do not include this parameter in subclass addStep method.) * * @return New length of the steps array. */ protected function _addStep(item:IPlayable, addToLastStep:Boolean=false, stepTypeAsClass:*=null): int { if (item is SequenceStep && !addToLastStep) { return _addStepAt(_steps.length, item); } if (!stepTypeAsClass) stepTypeAsClass = SequenceStep; var step:SequenceStep = (addToLastStep && _steps.length > 0 ? (_steps.pop() as SequenceStep) : new stepTypeAsClass() as SequenceStep); step.addChild(item); return _addStepAt(_steps.length, step, stepTypeAsClass); // adds listeners } /** * Developers: Add a method called <code>addStep</code> to your subclass as in Sequence. * * <p>Drop the third parameter in your subclass' addStep method. Use it to be sure * the correct type of wrapper is created, as in SequenceCA.</p> * * @param index Position in the array starting at 0, or a negative * index like Array.splice. * * @param item The playable item to splice into the sequence. * * @param stepTypeAsClass Type for SequenceSteps. (Do not include this parameter in subclass addStep method.) * * @return New length of the steps array. */ protected function _addStepAt(index:int, item:IPlayable, stepTypeAsClass:*=null): int { if (_state!=STOPPED) stop(); if (!stepTypeAsClass) stepTypeAsClass = SequenceStep; var step:SequenceStep = (item is SequenceStep ? item as SequenceStep : new stepTypeAsClass(item) as SequenceStep); step.addEventListener(SequenceEvent.ADVANCE, onStepEvent, false, 0, true); step.addEventListener(GoEvent.STOP, onStepEvent, false, 0, true); _steps.splice(index, 0, step); return _steps.length; } /** * Developers: Add a method called <code>addStep</code> to your subclass as in Sequence. * * @param index Position in the array starting at 0, or a negative * index like Array.splice. * * @return Developers: return the correct SequenceStep type for your subclass in your corresponding public method. */ protected function _removeStepAt(index:int) : * { if (_state!=STOPPED) stop(); var step:SequenceStep = _steps.splice(index, 1) as SequenceStep; step.removeEventListener(SequenceEvent.ADVANCE, onStepEvent); step.removeEventListener(GoEvent.STOP, onStepEvent); return step; } // -== Protected Methods ==- /** * @private * Internal handler for step advance. * * @param event SequenceEvent dispatched by child item. */ protected function onStepEvent(event : Event) : void { // A stop() call to the sequence results in step dispatching STOP, which would recurse here. if (_state==STOPPED || event.target!=_steps[_index]) return; // Only occurs if the SequenceItem is manually stopped outside of this manager. if (event.type==GoEvent.STOP) { stop(); return; } // Normal step advance if (event.type==SequenceEvent.ADVANCE) { if (_steps.length-_index == 1) { complete(); } else { advance(); } } } /** * @private * Internal handler for group completion. */ protected function advance() : void { if (_steps.length-_index > 1) { _index ++; // this changes currentStep value in following code _getCurrentStep().start(); } dispatchEvent(new SequenceEvent( SequenceEvent.ADVANCE )); } /** * @private * Internal handler for group completion. */ protected function complete() : void { // order-sensitive if (_repeater.next()) { dispatchEvent(new GoEvent( GoEvent.CYCLE )); _index = 0; _getCurrentStep().start(); } else { _index = _steps.length - 1; stop(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -