Brian
Brian

Reputation: 1893

How do I pass data between flash and javascript

I have a flash/flex object that is generating xml based on user interactions. I want to pass an xml string to javascript so that it can make a web service call.

How do I pass the XML back to Javascript?

examples:

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 to initialized

 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);

Javascript to get XML from flash/flex

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

Upvotes: 0

Views: 1495

Answers (1)

Gurpreet Singh
Gurpreet Singh

Reputation: 21233

You need to use ExternalInterface.call:

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

More information available here

Upvotes: 6

Related Questions