Flash adapter

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article



Use FlashOverlay API.


Lua-Flash player adapter is a wrapper of Flash External API for Lua. This adapter allows you to create Flash player layer on the application window, load SWF file on it, and call external methods in the Flash movie. You can also define callback functions which called from Flash movie.

More about Flash External API please refer following documents by Adobe:


  • You cannot make translucent Flash movie because the Flash player and main window are totally separated.

DOM<->Lua table translator

DOM by Lua table

To communicate with Flash movie, you need to build XML document. In this adapter, you can pass and receive an XML DOM represented as a Lua table.

The format of this DOM table is:

  • element ::= {"tagname", [at={attribute1=value1 [,attribulte2=value2, ...]}][, content]}
  • content ::= {element1 [, element2, ...]} | "string"


Element without children


{"invoke", at = {name = "showCustomizeWindow", returntype = "xml"}}


<invoke name="showCustomizeWindow" returntype="xml"/>

Complex element with child nodes


{"arguments", {
    {"object", {
        {"property", at = {id = "category"}, {
            {"string", "hair"}}},
        {"property", at = {id = "slot"}, {
            {"string", "head"}}},
        {"property", at = {id = "id"}, {
            {"string", "3"}}},


    <property id="category">
    <property id="slot">
    <property id="id">

API Reference


local ovl = FlashOverlay.Create (table, url)

table: Method callback table which maps from method name to function which takes one argument. This argument contains one <arguments> element which contains method call arguments. See example code below.

url: URL of a SWF file.

Return value: Flash overlay object (userdata).

Note: This object must be deleted with Delete method after using it.

Creates a new Flash overlay object. This object contains a Flash player and loads the SWF file specified by url parameter.


local h = {
   customizeResponse =
      function (res)
         -- res is a table like:
         -- {"arguments", {
         --  {"object", {
         --      {"property", at = {id = "id"}, {
         --          {"string", "11"}}},
         --      {"property", at = {id = "category"}, {
         --          {"string", "shoes"}}},
         --      {"property", at = {id = "slot"}, {
         --          {"string", "ankle"}}},
         -- }}}}
         local data = object2table (res[2][1][2])
         dump (data, true)
   closeCustomizeResponse =
      function (res)
         System.LogAlways ("ARAvatar.OpenAvatarCustomization: closeCustomizeResponse")
         dump (res, true)
local ovl = FlashOverlay.Create (h, "http://www.avarl.com/bluemars/bin/AvatarCustomize.swf")


FlashOverlay.Delete (ovl)

ovl: Flash overlay object.

Return value: none.

Deletes specified Flash overlay object. Since Flash overlay object is never GCed, it remains on memory until it's deleted.


FlashOverlay.Show (ovl)

ovl: Flash overlay object.

Return value: none.


FlashOverlay.Hide (ovl)

ovl: Flash overlay object.

Return value: none.


FlashOverlay.CallMethod (ovl, dom)

ovl: Flash overlay object.

dom: Flash external API XML document represented as a Lua table.

Return value: none.

Calls external function in the Flash movie. The dom must contain a "invoke" element. For more detail, please refer: http://livedocs.adobe.com/flex/201/html/19_External_Interface_178_5.html#129484


FlashOverlay.CallMethod (ovl, {"invoke", at = {name = "showCustomizeWindow", returntype = "xml"}})
Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools