Getting started with ActionScript: meebo Flash component API

Starter files

Download the meebo platform starter pack - ActionScript 2.
or
Download the meebo platform component - ActionScript 3 and the AS3 class documentation.

Getting the component installed

* This example is for Adobe Flash 8 Professional

1. Copy the Meebo.swc Flash Component File into your components directory, generally located here:

    C:\Program Files\Macromedia\Flash 8\en\Configuration\Components
2. If you already have Flash open, goto the Components Panel (Window -> Components) and click 'Reload' from the panel context menu. You should see the new Meebo component listed.

3. Create a new flash project or open up an existing project

4. Drag the Meebo component in the Components Panel into your project's Library Panel. You do not need to create an instance of the Meebo component, just add it to your library.

At this point, the Meebo class will be available to any ActionScript files associated with your project.

Connecting to meebo

* Note: A demo project is included with full source (meebo_platform_test.fla)

Applications will be loaded inside an IFrame in a meebo IM window. When loaded, four parameters will be passed as a query string to the app URL you have specified for your application's location (when you registered your app). Your code will be responsible for parsing the parameters for use with the meebo API.

The parameters are:

  • app_instance_id: application id, pass to meebo.registerApp
  • platform_instance_id: platform instance id, pass to meebo.init
  • time: a Unix timestamp
  • hash: a hash of the parameters combined w/ the shared secret

Note: meeboapputils.py is a CGI script will verify that a given set of arguments is valid and has been signed using the meebo/application shared secret. To use, find the get_secret function in the file and fill in your shared secret.

def get_secret(app_name):
    return "YOUR SHARED SECRET HERE"

Initialization

General flow for getting your application fully connected to the meebo session:
  1. In your ActionScript, parse out and store the parameters passed in by the URL.

    /* 
     * Grabs all of the url parameters and stores 
     * them into the location.args hash 
     */
    var location = {}
    location.href = this._url;
    var urlSearchIndex = location.href.indexOf("?");
    if (urlSearchIndex != -1) {
        location.search = location.href.substr(urlSearchIndex+1);
        location.args = { };
        var args = location.search.split("&");
        for (var i = 0;i < args.length; i++) {
            var arg = args[i].split("=");
            location.args[arg[0]] = unescape(arg[1] || true);
        }
        location.fullpath = location.href.substr(0,urlSearchIndex);
    }
    
    /*
     * Start meebo application code!
     */
    var app_instance_id = location.args['app_instance_id'];
    var platform_instance_id = location.args['platform_instance_id'];
    var meebo;
    
    
  2. Register any callback functions to handle asynchronous events coming back from meebo using the registerCallback method.

    meebo = new Meebo(platform_instance_id); meebo.registerCallback(meebo.USERCB_REGISTERED, registered); meebo.registerCallback(meebo.USERCB_RECEIVEMSG, receiveMsg); meebo.registerCallback(meebo.USERCB_JOIN, join); meebo.registerCallback(meebo.USERCB_LEAVE, leave); meebo.registerCallback(meebo.USERCB_CHANGEALIAS, changeAlias); meebo.registerCallback(meebo.USERCB_ERROR, error);
  3. Call registerApp method with the app_instance_id.

    meebo.registerApp(app_instance_id);
  4. Call onStart method to let meebo know that everything is setup.

    meebo.onStart();
  5. Upon being registered, you'll be connected to the meebo session and will then be able to receive and send meebo API events!

Callbacks

As noted above, you'll have to register a select number of callbacks. They are as following (feel free to copy the code snippets, they will print out debug statements to the application window):

  • registered(): The application has been successfully registered.

    function registered() { }
  • receivemsg(msg): Incoming message from the Application or a user.

    function receiveMsg(msg) {
        outputStr('RECEIVEMSG\n' + msg);
    }
  • join(user): User has joined the room. Parameter is a user object.

    function join(user) {
        outputStr('JOIN\n' + userToString(user))
        meebo.sendMsg(user, meebo.MSG_TYPE_APP);
        meebo.sendMsg('platform test says ' + user.alias + ' has joined the room', meebo.MSG_TYPE_IM);
    }
  • leave(user): User has left the room. Parameter is a user object.

    function leave(user) {
        outputStr('LEAVE\n' + userToString(user))
    }
  • changealias(user): User has changed his alias. Parameter is a user object.

    function changeAlias(user) {
        outputStr('CHANGEALIAS\n' + userToString(user))
    }
  • error(error_code, error_msg): An error has occurred.

    function error(code, msg) { }
    
  • debug(msg): Platform emits a debug message.

    function debug(msg) { }
    

Messaging

We provide a primitive framework for sending and receiving different types of messages between instances/participants of your application. You can create a multi-player game simply using the message passing system within the meebo platform.

sendMsg(msg, msg_type, alias = null);

There are 2 types of messages:

  • MSG_TYPE_APP: Messages will be delivered to the application for handling. Use this type to pass data messages back and forth. msg must be an Object:

    { player : 'username', move : 'k2' }

    meebo.sendMsg({
        type: "action",
        isAlive: "true",
        name: "futurama"
    }, meebo.MSG_TYPE_APP);
    
  • MSG_TYPE_IM: Messages will be delivered to the IM window chat history for display. msg must be a string.

    meebo.sendMsg('platform test says ' + user.alias + ' has joined the room', meebo.MSG_TYPE_IM, null);