如何在flash和javascript之间传递数据

时间:2012-11-29 15:58:07

标签: javascript flex

我有一个flash / flex对象,它根据用户交互生成xml。 我想将一个xml字符串传递给javascript,以便它可以进行Web服务调用。

如何将XML传回Javascript?

的示例:

HTML:

     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"
                id="My">
 <param name="movie" value="My.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="allowFullScreen" value="true" />
      </object>

javascript初始化

 var swfVersionStr = "10.2.0";
 var xiSwfUrlStr = "playerProductInstall.swf";
 var flashvars = {};

 var attributes = {};
 flashvars.servicePath = "services/";
 flashvars.isSaved = "false";
 flashvars.savedXML;
 var params=   {
            quality = "high";
            bgcolor = "#ffffff";
            allowscriptaccess = "sameDomain";
            allowfullscreen = "true";
            wmode = "transparent";
        };

  swfobject.embedSWF(
                "My.swf", "flashContent",
                "100%", "100%",
                swfVersionStr, xiSwfUrlStr,
                flashvars, params, attributes);

从Flash / flex获取XML的Javascript

var flashObject = document.contentWindow.getFlashObject();
flashObject.saveXml();
var xmlFromFlex = flashObject.savedXML; /*This is where I don't know how to get/set*/

1 个答案:

答案 0 :(得分:6)

您需要使用 ExternalInterface.call

import flash.external.*; 
var JSvalue:String; 
JSvalue = ExternalInterface.call('JsTestFunction','Work_Damn_It'); 

提供更多信息here