Jump to content
Sign in to follow this  
dnainby

flash to javascript communication

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

Share this post


Link to post
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" />

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...