How to call JavaScript function from with in Flash application?

假如想象 提交于 2019-12-11 15:47:07

问题


So in my AS file I want to call a function like

        public function JS(streamUri:String):void{
        JavascriptCommand(streamUri)
        }

to get my JS code running...

How to do such thing (Example needed)


回答1:


It sounds like you're looking for ExternalInterface.call(). Adobe has an article about how to use it to call JavaScript from ActionScript.

You can also use ExternalInterface to expose ActionScript to JavaScript and call functions internal to your SWF from JavaScript.

Let's say you have a JavaScript function that looks like this:

function specialAlert(msg) {
  alert(msg);
}

From your flash file you can call it like this:

import flash.external.*;

ExternalInterface.call("specialAlert", "Hi mom!");

And your JavaScript function should be called and alert the user "Hi mom!".




回答2:


Here's how to call JS from flex: http://www.switchonthecode.com/tutorials/flex-javascript-basics-using-externalinterface



来源:https://stackoverflow.com/questions/2741086/how-to-call-javascript-function-from-with-in-flash-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!