Rebase

Abstract

Download

Source code is available under a GPL license, in the public hg repository here: http://open.zoomorama.com/hg/as3.rebase/.

The current official release is 20091220-0.1.

Requirements

This is meant to be usable with Flex SDK 3.4 or greater.

Documentation

ExternalInterfaceNG

Has exactly the same signature as the original ExternalInterface, except for the addition of an extra method:

    public static function jsThrow( message: String ): void

The main difference with the native class is that you can actually rely on the value of the “available” property.

CapabilitiesNG

This has the same signature as the original Capabilities class except that:

  • fix the naming change on isAcrobatEmbed
  • add three additional properties
    public function get BrowserVersion():Number
    public function get OperatingSystem():String
    public function get Browser(): String

These additional informations will default to “unknown” and 0 if scripting is not possible in your application context.

Technically, these are what you would expect if working in javascript (see the Capabilities.js file for details).

ZMError

This simple extension to the native Error class makes available the following getters:

    public static function get ERROR_NOT_INITIALIZED() : ZMError
    public static function get ERROR_ALREADY_INITIALIZED() : ZMError
    public static function get ERROR_NOT_IMPLEMENTED() : ZMError
    public static function get NOT_FOUND_ERR() : ZMError
    public static function get FATAL() : ZMError

Uload

If your application has the rights to script, you can be notified that the embedding webpage has been closed or navigated away.

Usage is very simple:

  ULoad.instance.enable( m_Dispatcher );

where the signature of enable is:

    public function enable( value: IEventDispatcher ):void

Whenever the page quits, an Event.UNLOAD is dispatched onto your IEventDispatcher object.

WackyWheels

To have mousewheel support in contexts where the plugin is broken, simply do a:

  WackyWheels.instance.enable( m_Dispatcher );

with signature:

    public function enable( value: IEventDispatcher ):void

MimeService

The MimeService embeds a number of the most widely used mimetypes, and provides a couple of methods to manipulate them, namely:

    public function getTypeFromExtension( extension : String ): String
    public function getPrimaryExtensionFromType( type : String ): String
    public function getExtensionsFromType( type : String ): Array

HTML4Colors and SVGColors

These two simply provide constants shortcuts to the officially defined colors (HTML4 and SVG), nothing more.

Initialize

The usage of this singleton is straightforward:

    public function fromXML( obj: Object, iFace: Class, xmlNode: XMLList ): void
    public function fromJSON( obj: Object, iFace: Class, node: Object ): void

Given the object “obj”, the “iFace” interface that it implements will be enumerated, and all readwrite accessors will be populated with an identically named value in the passed “node”.

Please note the following important points:

  • if “iFace” extends another interface, this parent interface will be enumerated as well
  • values from the json (or xml) node will be typecasted to match the type in the interface
  • readonly, or writeonly accessors obviously won't be touched
  • if no value is found in the node for the given accessor, nothing will happen

Logger

Using the logger is quite simple.

First, your application should pick a setting for what level of error reporting you desire:

For example, this will report *everything*:

      ErrorLogger.instance.level = ErrorLogger.DEBUG | ErrorLogger.ERROR | ErrorLogger.FATAL | ErrorLogger.INFO | ErrorLogger.WARNING;

while this will just report error and fatal conditions:

      ErrorLogger.instance.level = ErrorLogger.ERROR | ErrorLogger.FATAL;

Secondly, you need to tell the logger what backend it should use:

      ErrorLogger.instance.backends = ErrorLogger.AS_TRACE | ErrorLogger.JS_INLINE;

This above will “trace” AND use an HTML constructed console.

Currently available backends are:

    // html built console
    public static const JS_INLINE : int = 1;
    // usual trace...
    public static const AS_TRACE  : int = 2;
    // terminal dump
    public static const JS_DUMP   : int = 4;
    // javascript "console" call
    public static const JS_CONSOLE: int = 8;
    // not implemented yet
    public static const FLASH_DUMP: int = 16;
    public static const SERVER_POST : int = 32;

The global setup being done, you may use any of the following methods wherever in your code:

      ErrorLogger.instance.info("some info", "whatever", "thing");
      ErrorLogger.instance.warning("some warning", "whatever", "thing");
      ErrorLogger.instance.debug("some debug", "whatever", "thing");
      ErrorLogger.instance.error("some error", "whatever", "thing");
      try{
        ErrorLogger.instance.fatal("some fatal error", "whatever", "thing");
      }catch(e: Error){
        // Fatal conditions call will obviously throw
      }

      try{
        ErrorLogger.instance.assert(boolean, "whatever", "thing");
      }catch(e: Error){
        // Failing assertions will obviously throw
      }

Important notes:

  • in order to enjoy the eyecandyness of the html inline backend, you need to copy the “rebase” directory (located under “debug”) along the webpage embedding your swf
  • you shouldn't use multiple JS backends simultaneously

Note about conditional compilation

The rebase project makes use of conditional compilation flags, that you should add to your compiler settings, namely:

  • -define=CONFIG::debug,false
  • -define=CONFIG::errorlogger,true

The “debug” flag should always be false unless you are planning to debug the rebase library itself…

The “errorlogger” flag should be set to true if you expect anything to come out from ErrorLogger calls. It may be turned to false as a mean to reduce the footprint when releasing an application officially, while still letting calls into your code. It's not really recommended if you still plan on obtaining debugging informations from it though (you may rather pay the price for the additional code, and mute it down in production by picking the right backend and/or error level reporting).

Back to top
en/opensource/as3/rebase.txt · Last modified: 2009/12/20 00:31 by Olivier Gambier