Sequence
Kind of class: | public class |
---|---|
Package: | org.casalib.time |
Inherits from: | Process < RemovableEventDispatcher < EventDispatcher |
Implements: | |
Version: | 12/26/08 |
Author: | Jon Adams, Aaron Clinger |
Classpath: | org.casalib.time.Sequence |
File last modified: | Wednesday, 31 December 2008, 20:18:28 |
Creates a sequence of methods calls that wait for a specified event and/or delay.
Example:
-
package { import flash.display.MovieClip; import flash.display.Sprite; import org.casalib.time.Sequence; import org.casalib.events.SequenceEvent; public class MyExample extends MovieClip { protected var _sequence:Sequence; protected var _box:Sprite; public function MyExample() { this._box = new Sprite(); this._box.graphics.beginFill(0xFF00FF); this._box.graphics.drawRect(0, 0, 250, 250); this._box.graphics.endFill(); this.addChild(this._box); this._sequence = new Sequence(true); this._sequence.addTask(this._hideBox, 3000); this._sequence.addTask(this._showBox, 1000); this._sequence.addEventListener(SequenceEvent.LOOP, this._onLoop); this._sequence.start(); } protected function _hideBox():void { this._box.visible = false; } protected function _showBox():void { this._box.visible = true; } protected function _onLoop(e:SequenceEvent):void { trace("Sequence has looped " + e.loops + " times."); } } }
With events:
package { import flash.display.MovieClip; import flash.display.Sprite; import fl.motion.easing.Bounce; import fl.motion.easing.Elastic; import fl.motion.easing.Linear; import org.casalib.time.Sequence; import org.casalib.transitions.PropertyTween; import org.casalib.events.TweenEvent; public class MyExample extends MovieClip { protected var _sequence:Sequence; protected var _box:Sprite; protected var _slideOver:PropertyTween; protected var _slideDown:PropertyTween; protected var _rotate:PropertyTween; public function MyExample() { this._box = new Sprite(); this._box.graphics.beginFill(0xFF00FF); this._box.graphics.drawRect(0, 0, 50, 50); this._box.graphics.endFill(); this.addChild(this._box); this._slideOver = new PropertyTween(this._box, "x", Linear.easeNone, 100, 1); this._slideDown = new PropertyTween(this._box, "y", Bounce.easeOut, 200, 4); this._rotate = new PropertyTween(this._box, "rotation", Elastic.easeOut, 720, 10); this._sequence = new Sequence(); this._sequence.addTask(this._slideOver.start, 0, this._slideOver, TweenEvent.COMPLETE); this._sequence.addTask(this._slideDown.start, 2000, this._slideDown, TweenEvent.COMPLETE); this._sequence.addTask(this._rotate.start, 1000, this._rotate, TweenEvent.COMPLETE); this._sequence.start(); } } }
Events broadcasted to listeners:
- SequenceEvent with type:
START
- Dispatched when Sequence starts. - SequenceEvent with type:
STOP
- Dispatched when Sequence stops. - SequenceEvent with type:
RESUME
- Dispatched when Sequence is resumed. - SequenceEvent with type:
LOOP
- Dispatched when Sequence is completed and is looping. - SequenceEvent with type:
COMPLETE
- Dispatched when Sequence has completed.
Summary
Constructor
- Sequence (isLooping:Boolean = false)
- Creates a new Sequence.
Class properties
Class properties inherited from Process
Instance properties
- looping : Boolean
- Indicates if the Sequence repeats once completed true; or stops false.
- loops : uint
- The number of times the sequence has run since it started.
Instance properties inherited from Process
Instance properties inherited from RemovableEventDispatcher
Instance methods
- addTask (closure:Function, delay:Number = 0, scope:IEventDispatcher = null, completeEventName:String = null, position:int = -1) : void
- Adds a method to be called to the Sequence.
- removeTask (closure:Function) : void
- Removes a method from being called by the Sequence.
- start : void
- Starts the Sequence from the beginning.
- stop : void
- Stops the Sequence at its current position.
- resume : void
- Resumes sequence from stopped position.
- destroy : void
Instance methods inherited from RemovableEventDispatcher
Constructor
Sequence
public function Sequence (
isLooping:Boolean = false)
Creates a new Sequence.
Parameters:
isLooping:
Indicates if the Sequence repeats once completed
true
; or stops false
.Instance properties
looping
public looping:Boolean
(read,write)
Indicates if the Sequence repeats once completed
true
; or stops false
. Instance methods
addTask
public function addTask (
closure:Function,
delay:Number = 0,
scope:IEventDispatcher = null,
completeEventName:String = null,
position:int = -1) : void
Adds a method to be called to the Sequence.
Parameters:
closure :
The function to execute.
delay :
The time in milliseconds before the method will be called.
scope :
The event dispatcher scope in which to listen for the complete event.
completeEventName:
The name of the event the class waits to receive before continuing.
position :
Specifies the index of the insertion in the sequence order; defaults to the next position.
removeTask
public function removeTask (
closure:Function) : void
Removes a method from being called by the Sequence.
Parameters:
closure:
The function to remove from execution.
resume
public function resume (
) : void
Resumes sequence from stopped position.
Events broadcasted to listeners:
- SequenceEvent with type:
RESUME
- Dispatched when Sequence is resumed.
Specified by:
start
override public function start (
) : void
Starts the Sequence from the beginning.
Events broadcasted to listeners:
- SequenceEvent with type:
START
- Dispatched when Sequence starts.
Overrides:
Specified by:
stop
override public function stop (
) : void
Stops the Sequence at its current position.
Events broadcasted to listeners:
- SequenceEvent with type:
STOP
- Dispatched when Sequence stops.
Overrides:
Specified by: