LoopCommand

Kind of class:public class
Package:com.bourre.commands
Inherits from:AbstractSyncCommand < AbstractCommand
Implements:
Author:Cédric Néhémie
Classpath:com.bourre.commands.LoopCommand
File last modified:Monday, 24 November 2008, 11:36:52
A LoopCommand wrap a loop statement within a command. Loop
are strecthed over time using functionnalities of a TickBeaconobject. According to the maximum execution time limit of this command
the maximum amout of iteration will be performed for each step since the
step execution time exceed the maximum execution time.

For informations and examples on these classes see the
How to use LoopCommand
and IterationCommand
document.

See also:

Summary


Constructor
  • LoopCommand (command:IterationCommand, iterationLimit:Number = DEFAULT_ITERATION_TIME_LIMIT)
    • Creates a new LoopCommand object which will handle
Constants
Instance methods
Event handlers
  • onLoopStartEVENT : String
    • Name of the event dispatched at the start of the command's process.
  • onLoopStopEVENT : String
    • Name of the event dispatched at the stop of the command's process.
  • onLoopProgressEVENT : String
    • Name of the event dispatched at each step of computation.
  • onLoopEndEVENT : String
    • Name of the event dispatched at the end of the command's process.
  • onLoopCancelEVENT : String
    • Name of the event dispatched on user cancelation.
  • onTick (e:Event = null) : void
    • Process the loop.
  • onCommandEnd (e:Event) : void
    • Called at the end of another loop command.

Constructor

LoopCommand

public function LoopCommand (
command:IterationCommand, iterationLimit:Number = DEFAULT_ITERATION_TIME_LIMIT)

Creates a new LoopCommand object which will handle
the passed-in IterationCommand
Parameters:
command :
iteration command which will be called
during the loop, it also provide the
iterator the loop command will use
iterationLimit:
maximum execution time for each step of
the loop command process

Constants

DEFAULT_ITERATION_TIME_LIMIT

public static const DEFAULT_ITERATION_TIME_LIMIT:Number = 15
(read)

Default execution time limit by loop iterations group

NO_LIMIT

public static const NO_LIMIT:Number = Number.POSITIVE_INFINITY
(read)

Defines an unlimited execution time for loop iterations.

Instance methods

addLoopCommandListener

public function addLoopCommandListener (
listener:LoopCommandListener) : Boolean

Adds the passed-in listener as listener for this command's events.
Parameters:
listener:
listener to be added

cancel

public function cancel (
) : void

Attempts to cancel execution of this task.
This attempt will fail if the task has already completed,
has already been cancelled, or could not be cancelled for
some other reason. If successful, and this task has not
started when cancel is called, this task should never run.

After this method returns, subsequent calls to isRunningwill always return false. Subsequent calls to

run will always fail with an exception. Subsequent
calls to cancel will always failed with the throw
of an exception.

Throws:
  • {VISDOC_LINK_0}IllegalStateException — if the cancel method have been called wheras the operation have been already
    cancelled

execute

override public function execute (
e:Event = null) : void

Resets and then start the loop command process.

The command cannot be executed after a call to
the cancel method. If a call to

execute
is done after the command be canceled
the function fail and throw an error

Parameters:
e:
event object to initialise the command (not use)
Throws:
  • {VISDOC_LINK_0}IllegalStateException — if the execute method have been called wheras the operation have been already
    cancelled
Overrides:
  • AbstractSyncCommand.execute

isCancelled

public function isCancelled (
) : Boolean

Returns true if the loop process have been
canceled by the user.
Returns:
  • true if the loop process have been
    canceled by the user

isDone

public function isDone (
) : Boolean

Returns true if the loop process have been
completed.
Returns:
  • true if the loop process have been
    completed

removeLoopCommandListener

public function removeLoopCommandListener (
listener:LoopCommandListener) : Boolean

Removes the passed-in listener as listener for this command's events.
Parameters:
listener:
listener to be removed

reset

public function reset (
) : void

Resets the state of this command. A loop command cannot be reset
while running. If a call to the reset is done
while the command is running, the call fail with an error.
Throws:
  • {VISDOC_LINK_0}IllegalStateException — Can't reset an
    operation currently running.

setFrameBeacon

public function setFrameBeacon (
beacon:TickBeacon) : void

Defines on which beacon the loop command will perform
its operation. It allow to the user to control the
speed at which execution steps will be called.
Parameters:
beacon:
beacon object onto which the command
will run

setOwner

override public function setOwner (
owner:Plugin) : void

Overrides:
  • AbstractSyncCommand.setOwner

start

public function start (
) : void

Starts or restarts the loop process.
The process can be started only if there is a valid

IterationCommand and if the command
haven't be canceled or completed.
Throws:
  • {VISDOC_LINK_0}IllegalStateException — Can't start
    a command which has no specified iteration command
  • {VISDOC_LINK_1}IllegalStateException — Can't start a
    canceled or completed command

stop

public function stop (
) : void

Stops the loop process. Command could be
stop only when it is running.

Event handlers

onCommandEnd

public function onCommandEnd (
e:Event) : void

Called at the end of another loop command.
The LoopCommand class implements

ASyncCommandListener in order to
provide a way to automatically chain several
commands together.
Parameters:
e:
event object dispatched by the asynchronous command

onLoopCancelEVENT

public static const onLoopCancelEVENT:String = "onLoopCancel"
(read)

Name of the event dispatched on user cancelation.

onLoopEndEVENT

public static const onLoopEndEVENT:String = "onLoopEnd"
(read)

Name of the event dispatched at the end of the command's process.

onLoopProgressEVENT

public static const onLoopProgressEVENT:String = "onLoopProgress"
(read)

Name of the event dispatched at each step of computation.

onLoopStartEVENT

public static const onLoopStartEVENT:String = "onLoopStart"
(read)

Name of the event dispatched at the start of the command's process.

onLoopStopEVENT

public static const onLoopStopEVENT:String = "onLoopStop"
(read)

Name of the event dispatched at the stop of the command's process.

onTick

public function onTick (
e:Event = null) : void

Process the loop. At each call of this function
a real loop statement is performed until its
execution time go past the maximum execution time
defined for this command.
Parameters:
e:
event object dispatched by the beacon
Specified by: