Skip to content

Instantly share code, notes, and snippets.

@brian428
Forked from swiz/IAutonomousChainStep.as
Created November 30, 2010 02:45
Show Gist options
  • Save brian428/721058 to your computer and use it in GitHub Desktop.
Save brian428/721058 to your computer and use it in GitHub Desktop.
public class BaseCompositeChain extends AbstractChain implements IChain
{
public function BaseCompositeChain( mode:String = ChainType.SEQUENCE, stopOnError:Boolean = true )
{
super( mode, stopOnError );
}
public function doProceed():void
{
if( currentStep is IAutonomousChainStep )
IAutonomousChainStep( currentStep ).doProceed();
else if( currentStep is IChain )
IChain( currentStep ).start();
}
}
public function doEventChain() : void
{
var eventChain : EventChain = new EventChain( dispatcher );
eventChain.addEventListener( ChainEvent.CHAIN_COMPLETE, handleChainComplete, false, 0, true );
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.USER_SCREEN_ACTIVE ) ) );
eventChain.addStep( new EventChainStep( new UserEvent( UserEvent.USER_PROCESSING_COMPLETE ) ) );
eventChain.start();
}
[EventHandler( event="UserEvent.USER_SCREEN_ACTIVE" )]
public function logUserScreenActive() : void
{
// perform logic or dispatch events when the user screen is active
}
[EventHandler( event="UserEvent.USER_PROCESSING_COMPLETE" )]
public function logUserProcessingComplete() : void
{
// perform logic or dispatch events when the processing finishes
}
public function handleChainComplete( event : Event ) : void
{
// perform logic or dispatch events when the chain is complete
}
public interface IAutonomousChainStep extends IChainStep
{
function doProceed():void;
}
public interface IChain extends IEventDispatcher
{
function get position():int;
function set position( value:int ):void;
function get isComplete():Boolean;
function get stopOnError():Boolean;
function set stopOnError( value:Boolean ):void;
function hasNext():Boolean;
function stepComplete():void;
function stepError():void;
function addStep( step:IChainStep ):IChain;
function start():void;
function doProceed():void;
}
public interface IChainStep
{
function get chain():IChain;
function set chain( value:IChain ):void;
function get isComplete():Boolean;
function complete():void;
function error():void;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment