Jump to content

flash to javascript communication


dnainby

Recommended Posts

Is it possible for flash 8 to communicate with javascript functions in a browser using either getURL() or fscommand() locally, ie not using a web server?I used to use fscommand(), but since upgrading to flash 8, this doesn't work anymore. I will only ever use this on local machines and never publish to the web.Thanks in advancedan

Link to comment
Share on other sites

You can use the flash ExternalInterfaceExternalInterface.call(function_name,parameter1,parameter2...)ExternalInterface.addCallback(method_name, instance, method)Run Javascript from flash:Actionscript:var my_btn:MovieClip = createButton(100, 30, 0xCCCCCC);my_btn.onRelease = function() {ExternalInterface.call("alertSomething", "This is a string"));}Javascript:function alertSomething(str) {alert(str);}Run Actionscript from java script:Actionscript:var instance:Object = null;var method:Function = something;var wasSuccessful:Boolean = ExternalInterface.addCallback("hello", instance, method);var txtField:TextField = this.createTextField("txtField", this.getNextHighestDepth(), 0, 0, 200, 50);txtField.border = true;txtField.text = "This is a string"function something() { txtField.text = "This string has been modified";}Javascript/HTML:<!-- Important: give the flash file an ID to reference it bylike this: <object id="FlashFile" ... --><input type="button" onclick="document.getElementById('FlashFile').hello()" value="Click to run Actionscript" />

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...