Skip to content
tsclausing edited this page Dec 31, 2010 · 11 revisions

Trigger: Dead simple Commands and application-wide Callbacks.

The introduction below defines an ActionScript class and a function to be used in a simple Hello World example.


Command: A class.

public class MyCommandClass {
    public function execute(...args) :void {
        // do something, like make a service call for data, perform some business logic, or return a value to the caller.
        trace("Hello World from a Command class");
    }
}

When Trigger executes a Command, it creates a new instance of the class and then invokes a method, returning any value back to the caller.


Callback: A function.

function myCallbackFunction(...args) :void {
    // do something, like change the state of your application or return a value to the caller.
    trace("Hello World from a Callback function");
}

When Trigger executes a Callback, it invokes the function, returning any value back to the caller.


Example: Add & trigger a Command and a Callback

Main.as

// Adding a Command
addCommand("trigger1", MyCommandClass);
// Adding a Callback
addCallback("trigger2", myCallbackFunction);

Anywhere.as

// Trigger the Command
trigger("trigger1");
// Trigger the Callback
trigger("trigger2");

Console Output

Hello World from a Command class
Hello World from a Callback function

This example illustrates the simplicity of Trigger. No configuration files, no classes to extend and no overt framework code in your application - just a simple global function API for Commands and Callbacks.


Where to go from here?

  1. Download the source or .swc here
  2. View an introductory application here
  3. Try it out and contribute to the project :)