flash data integration:
Hi,
I'm having trouble integrating the Javascript Proxy code into my AS2 class .
The tests using the proxy on the root of an swf worked fine, and it can't
figure out whats going wrong in this new enviroment.
Communication from flash to Javascript is working fine, but we can't get
javascript to call a flash function.
Code below. Any advice much appreciated.
// CLASS CODE
import com.macromedia.javascript.JavaScriptProxy;
class loadData_online extends MovieClip
{
// declare vars
public var proxy:JavaScriptProxy;
// the presentation class that owns me
private var owner:Object;
// used everytime XML is loaded
private var loadXML:XMLextends;
// general function object
private var gen_functions:Object;
// class declaration
function loadData_online()
{
trace("new loadData_online " + this);
// *****************************************************
// *****************************************************
// set up proxy connection
// using "this" as callback scope isnt allowing the javascript
to
// call a method in this class
// *****************************************************
// *****************************************************
proxy = new JavaScriptProxy(_root.lcId, this);
_root.retrievedData.text += newline + "proxy: " + proxy;
_root.retrievedData.text += newline + "scope: " + this;
// register an instance of the general function
gen_functions = new general_functions();
}
// sets who owns this class
public function loadData_registerOwner(param_owner:Object):Void
{
//trace("loadData_offline: " + "owner registered=" + param_owner);
owner = param_owner;
}
//-----------------------------------------------------------------------------
--------
// JS FUNCTIONS
// COMMANDS OUT
//
//
// sends requests to javascript for
// data to be passed back to the flash
//
// type = "slide" or "template" or "presentation"
// id = slideRevisionID, templateID, presentationID
private function send_getJSData(param_type, param_id):Void
{
trace("sending JS request - getJSData");
_root.retrievedData.text += newline + "send_getJSData " + param_type + " " +
param_id;
proxy.call("getJSData", param_type, param_id);
}
// COMMANDS IN
//
// recieves all incomming data from JS
// sends it the relevant path
// params:
// type = "slide" or "template" or "presentation"
// id = slideRevisionID, templateID, presentationID
// xml = the xml
public function setFlashData(param_type, param_id, param_xml):Void
{
trace("recieved flash data from JS");
_root.retrievedData.text += newline + "setFlashData " + param_type + " " +
param_id + " " + param_xml;
// convert data string
loadXML = new XMLextends();
loadXML.parseXML(param_xml);
// what type of data is it?
if(param_xml == "presentation")
{
loadData_presentation_loaded(loadXML.toObject());
}
}
// IN
// JS FUNCTIONS
//-----------------------------------------------------------------------------
--------
//
-----------------------------------------------------------------------------
// load presentation data
//
-----------------------------------------------------------------------------
// returns the data for the current presentation
public function loadData_presentation(param_presentationID):Void
{
trace("loadData_online: " + "loading presentation ID=" +
param_presentationID);
// triggers load
loadData_presentation_load(this, param_presentationID);
}
// actually loads the XML
private function loadData_presentation_load(caller, param_presentationID):Void
{
trace("loadData_online: " + "load presentation called: " +
param_presentationID);
// call js connection to get results
send_getJSData("presentation", param_presentationID);
}
}
// JS CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="
http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JavaScript/Flash API</title>
<script type="text/javascript" src="JavaScriptFlashGateway.js"></script>
<script type="text/javascript">
//<![CDATA[
// unique ID for proxy - timestamp
var uid = new Date().getTime();
// instantiate flash proxy using uid
var flashProxy = new FlashProxy(uid, 'JavaScriptFlashGateway.swf');
// javascript to flash
function setFlashData(type, id, xml) {
trace('setFlashData');
flashProxy.call('setFlashData', type, id, xml);
}
function getFlashData(type, id) {
trace('getFlashData');
flashProxy.call('getFlashData', type, id);
}
function doFlashAction(action) {
trace('doFlashAction');
flashProxy.call('doFlashAction', action);
}
function setFlashAsset(id, xml) {
trace('setFlashAsset');
flashProxy.call('setFlashAsset', id, xml);
}
// flash to javascript handlers
function getJSData(type, id) {
switch (type) {
case 'slide':
trace('getJSData: slide ' + id);
break;
case 'template':
trace('getJSData: template ' + id);
break;
case 'presentation':
trace('getJSData: presentation ' + id);
break;
}
setFlashData(type, id, 'this should be xml');
}
function setJSData(type, id, xml) {
switch (type) {
case 'slide':
trace('setJSData: slide ' + id + ' - ' + xml);
break;
case 'template':
trace('setJSData: template ' + id + ' - ' + xml);
break;
case 'presentation':
trace('setJSData: presentation ' + id + ' - ' + xml);
break;
}
}
function selectJSAsset(id, width, height) {
// popup a select box to choose an asset
// we may ignore the width and height - but they are used to filter on a
crop size
trace('selectJSAsset: id ' + id + '; width=' + width + ' height=' +
height);
}
// tracer
function trace(message) {
document.getElementById('trace').innerHTML += message + '\n';
}
//]]>
</script>
</head>
<body>
<h2>Flash object:</h2>
<script type="text/javascript">
//<![CDATA[
var tag = new FlashTag('my.swf', 300, 300); // last two arguments are
height and width
tag.setFlashvars('lcId='+uid);
tag.write(document);
//]]>
</script>
<h2>Trace info from JS:</h2>