CommandFPS

Kind of class:class
Inherits from:none
Implements:
Known subclasses:
Version:1.0
Author:Francis Bourre
Classpath:com.bourre.commands.CommandFPS
File last modified:Wednesday, 31 October 2007, 07:35:29
CommandFPS allows to store Command objects and to execute each one
at each frame displayed by the player.

If your animation framerate is 31 fps, each added command
will have its execute method triggered 31 times per second.

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

See below a basical example to understand the mechanism :

Example:
import com.bourre.commands.*;

var t:CommandFPS = new CommandFPS();
var d:Delegate = new Delegate(this, test);
var i:Number = 0;

function test(s:String) : Void
{
    trace("hello world");
    i++;
    if (i >= 10) t.remove(d);
}

t.push( d );

Constructor

CommandFPS

function CommandFPS (
)
Constructs a new CommandFPS instance.

That allows to store Command objects and to execute each one
at each frame displayed by the player.

Instance methods

delay

function delay (
oC:Command) : Void
Delay command execution to the next frame.
The passed command will be executed once.
Parameters:
oC:
Command instance to execute.
Example:
import com.bourre.commands.*;

var t:CommandFPS = new CommandFPS();

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

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

getLength

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

push

function push (
oC:Command) : String
Add Command object.
The passed command added will be executed each frame until you stop it temporarily
or remove it definitely.

This method returns a String, you can use it later as a hashcode
to stop, resume or remove your command.
Check pushWithName documentation to get more details on this topic.
Parameters:
oC:
Command instance to add.
Returns:
String Key name.

pushWithName

function pushWithName (
oC:Command, sN:String) : String
Add Command object.
The passed command added will be executed each frame until you stop it temporarily
or remove it definitely from CommandFPS instance.

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

Parameters:
oC:
Command instance to add.
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:CommandFPS = new CommandFPS(); var d:Delegate = new Delegate(this, test); function test() : Void; * { trace("hello world"); if (getTimer()>3000) t.removeWithName("key") } t.pushWithName(d, "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
Resume command previously stopped with stop or stopWithName methods.
Usage : t.resume( myCommand );
Parameters:
oC:
Command instance to resume.
Returns:
Boolean that indicates resume success.

resumeWithName

function resumeWithName (
sN:String) : Boolean
Resume 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 resume.
Returns:
Boolean that indicates resume success.

stop

function stop (
oC:Command) : Boolean
Stops command execution.
The targeted command won't be executed anymore until you resume 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 resume 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

Event handlers

onEnterFrame

function onEnterFrame (
) : Void
Don't use, overwrite or override this method.
That's the public callback of com.bourre.transitions.FBeacon used internally to run stored commands on each frame.