Flash adapter
From Blue Mars Developer Guidebook
|
|
Contents |
Overview
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:
- Using the External API http://livedocs.adobe.com/flex/201/html/19_External_Interface_178_1.html
- Example: Using the External API with an ActiveX container http://livedocs.adobe.com/flex/201/html/19_External_Interface_178_5.html
Limitation
- 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"
Example
Element without children
Lua:
{"invoke", at = {name = "showCustomizeWindow", returntype = "xml"}}
XML:
<invoke name="showCustomizeWindow" returntype="xml"/>
Complex element with child nodes
Lua:
{"arguments", {
{"object", {
{"property", at = {id = "category"}, {
{"string", "hair"}}},
{"property", at = {id = "slot"}, {
{"string", "head"}}},
{"property", at = {id = "id"}, {
{"string", "3"}}},
}}}}
XML:
<arguments>
<object>
<property id="category">
<string>hair</string>
</property>
<property id="slot">
<string>head</string>
</property>
<property id="id">
<string>3</string>
</property>
</object>
</arguments>
API Reference
Create
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.
Example
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)
end,
closeCustomizeResponse =
function (res)
System.LogAlways ("ARAvatar.OpenAvatarCustomization: closeCustomizeResponse")
dump (res, true)
end,
}
local ovl = FlashOverlay.Create (h, "http://www.avarl.com/bluemars/bin/AvatarCustomize.swf")
Delete
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.
Show
FlashOverlay.Show (ovl)
ovl: Flash overlay object.
Return value: none.
Hide
FlashOverlay.Hide (ovl)
ovl: Flash overlay object.
Return value: none.
CallMethod
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
Example
FlashOverlay.CallMethod (ovl, {"invoke", at = {name = "showCustomizeWindow", returntype = "xml"}})

