/************************************************************************* * File: mediascape.as * Description: Flash -> Mediascape / Mediascape -> Flash Communication Actionscript * Author: Ben Clayton * Created: 20 November 2006 * Copyright: Hewlett-Packard Laboratories ************************************************************************/ // variable that hold the mscape version as a string /* hpMscapeVersion */ // variable used to pass requests from mscape to run functions in actionscript /* hpFunctionCallData */ ///////////////////////////////////////////////////////////////// // C-Sharp-Message-Broadcaster Inspired by code from http://www.flashfanatiker.de/blog/archives/000032.html ///////////////////////////////////////////////////////////////// _root.bcCSharpMessage = function (varName, oldVal, newVal) { arguments.callee.broadcastMessage("onCSharpMessage", newVal); } AsBroadcaster.initialize(_root.bcCSharpMessage); _root.onLoad = function () { this.CSharpMessage = null; this.watch("hpFunctionCallData", this.bcCSharpMessage); } // Receive from C-Sharp, pass into makeFunctionCall obj = new Object(); obj.onCSharpMessage = function (strMessage) { trace(strMessage); hpMakeFunctionCall(strMessage); } _root.bcCSharpMessage.addListener(obj); ///////////////////////////////////////////////////////////////// // end inspired code // This function converts the string received by flash into a function call, then runs the function function hpMakeFunctionCall(functionCall) { CommandArray = functionCall.split("|"); //create parameter array var parameters = []; for (var j=1; j<(CommandArray.length); j++) { parameters.push(CommandArray[j]); } //get pointer to flash function with name CommandArray[1] var inputFunction = eval(CommandArray[0]); // call the required flash function with our params inputFunction.apply(null, parameters); // If we don't know which version of mscape we're using // assume we're using a pre 2.1 version which // requires a confirmation fscommand to be sent // each time a function finishes. if (hpMscapeVersion == undefined) { fscommand("hpFunctionComplete"); } }