CommandMS

Kind of class:class
Inherits from:none
Known subclasses:
Version:1.0
Author:Francis Bourre
Classpath:com.bourre.commands.CommandMS
File last modified:Wednesday, 31 October 2007, 07:35:29
CommandMS allows to store Command objects and to loop
their execution at a specified speed in milliseconds.

I encourage in most of cases to use singleton implementation : CommandManagerMS

In the Example below, the specified command will be runned each second :

Example:
import com.bourre.commands.*;

var t:CommandMS = new CommandMS();

function test(s:String) : Void
{
    trace("hello world");
}

t.push( new Delegate(this, test), 1000 );

Constructor

CommandMS

function CommandMS (
)
Constructs a new CommandMS instance.

That allows to store Command objects and to loop
their execution at a specified speed in milliseconds.

Instance methods

delay

function delay (
oC:Command, nMs:Number) : Void
Wait specified amount of time before executing the passed command.
The command will be executed once.

In this example, the method execution is 3 seconds delayed :

Parameters:
oC :
targeted Command Object to execute.
nMs:
Time delay before execution
Example:
import com.bourre.commands.*;

var t:CommandMS = new CommandMS();

function test() : Void;	 * {
    trace('hello world');
}

t.delay( new Delegate(this, test), 3000 );

getLength

function getLength (
) : Number
Get amount of commands stored.
Returns:
Number.

push

function push (
oC:Command, nMs:Number) : String
Add Command object.
The passed command added will be executed in a loop until
you stop it temporarily or remove it definitely.
You must specify time loop duration in milliseconds.

This method returns a String, you can use it later as a hashcode
to stop, restart or remove your command.
Check pushWithName documentation to get more details on this topic.

Parameters:
oC :
Command instance to add.
nMs:
Time loop duration in milliseconds.
Returns:
String Key name.

pushWithName

function pushWithName (
oC:Command, nMs:Number, sN:String) : String
Add Command object.
The passed command added will be executed in a loop until
you stop it temporarily or remove it definitely.
You must specify time loop duration in milliseconds.

It works exactly the same as push excepts it takes String as parameter.
This String will work as a hashcode for further stop (removeWithName),
removal (stopWithName) or restart (resumeWithName).

Parameters:
oC :
Command instance to add.
nMs:
Time loop duration in milliseconds.
sN :
(optional parameter) You can specify your own String key name.
Usage note:

If you provide an existing key, it will remove the associated command without any warning.

Another note, try to use this feature only when its absolutely required.
Generally, be careful about your design and objects encapsulation.
Don't make global references when it's not needed.

Example:
import com.bourre.commands.*; var t:CommandMS = new CommandMS(); var d:Delegate = new Delegate(this, test); function test() : Void; * { trace("hello world"); if (getTimer()>3000) t.removeWithName("key") } t.pushWithName(d, 500, "key"); d.execute();
Returns:
String Key name.

remove

function remove (
oC:Command) : Boolean
Remove command.
The passed command won't be executed anymore.
Usage : t.remove(myCommand);
Parameters:
oC:
Command instance to remove.
Returns:
Boolean that indicates remove success.

removeAll

function removeAll (
) : Void
Remove all commands.
Each command added will be removed, it means that they won't be executed anymore.
Warning, because you can't undo this method's behaviour.

removeWithName

function removeWithName (
sN:String) : Boolean
Remove command.
The passed command won't be executed anymore.

It works exactly the same as remove excepts it takes String as parameter.
You must pass a valid key to ensure it works.
The expected key is the String returned by push method while command addition.
Usage : t.removeWithName( "key" );

Parameters:
sN:
Command name (given key) to remove.
Returns:
Boolean that indicates remove success.

resume

function resume (
oC:Command) : Boolean
Restarts command previously stopped with stop or stopWithName methods.
Usage : t.resume( myCommand );
Parameters:
oC:
Command instance to restart.
Returns:
Boolean that indicates restart success.

resumeWithName

function resumeWithName (
sN:String) : Boolean
Restarts command previously stopped with stop or stopWithName methods.

It works exactly the same as resume excepts it takes String as parameter.
You must pass a valid key to ensure that works.
The expected key is the String returned by push method while command addition.
Usage : t.resume( "key" );

Parameters:
sN:
Command name (given key) to restart.
Returns:
Boolean that indicates restart success.

stop

function stop (
oC:Command) : Boolean
Stops command execution.
The targeted command won't be executed anymore until you restart it
with resume or resumeWithName methods.
Usage : t.stop(myCommand);
Parameters:
oC:
Command instance to stop.
Returns:
Boolean that indicates stop success.

stopWithName

function stopWithName (
sN:String) : Boolean
Stops command execution.
The targeted command won't be executed anymore until you restart it
with resume or resumeWithName methods.

It works exactly the same as stop excepts it takes String as parameter.
You must pass a valid key to ensure that works.
The expected key is the String returned by push method while command addition.
Usage : t.stopWithName( "key" );

Parameters:
sN:
Command name (given key) to stop.
Returns:
Boolean that indicates stop success.

toString

function toString (
) : String
Returns the string representation of this instance.
Returns:
the string representation of this instance