Tuesday, October 11, 2011

Transfer variables from Javascript in SWFobject to actionscript in a flash file



I am designing a flash swf file, which is used to test video connection setting in Flash Media Server. The IP address of the Flash Media Server should be passed from Javascript in SWFobject to  the actionscript in the flash file. My Javascript for SWFobject:
<div id="flashContent" class="flashContainer"></div>
   <script type="text/javascript">
   <!--//--><![CDATA[//><!--
   var so = new SWFObject("/_swf/fms_connection/settings.swf", "connection_settings", "640", "360","7");
   so.addParam("wmode", "transparent");
 so.addParam("flashvars", "fms_server=192.168.1.61&room_id='.$_SESSION['member_id'].'");   
so.write("flashContent");
   //--><!]]>
</script>

Pass variables  room_id and fms_server to the  actionscript in the flash file.
import flash.external.
ExternalInterface;

function onMouseDown():Void {
    focusManager.enabled = false;
}
function onMouseUp():Void {
    focusManager.enabled = true;
}

attachMovie("connectionSettings", "cs", 0);
var flash_id = "connection_settings"; //could retrive this dynamically with the _url param
function whereAmI(myLocation:String):Void {
    cs.myTrace("whereAmI: " + myLocation);
    cs.connect(room_id,myLocation,fms_server);
}
//don't put the swf in a form IE will crap out on ExternalInterface.addCallback
ExternalInterface.addCallback("sendToFlash", null, whereAmI);
getURL("javascript:var me=document."+flash_id+";me.sendToFlash(top.location.href);");
room_id and fms_serve are also passed to connetionSettings class, which is defined in another actionscript file.

No comments:

Post a Comment