AS2 - 获取javascript变量值

时间:2015-03-25 08:30:18

标签: javascript function variables actionscript-2 externalinterface

我希望简单地将JavaScript变量值传递给AS2。

的JavaScript

var myNewText = 'new variable value created';
var myNewLink = 'www.stackoverflow.com';

如何在AS2中获取vars值?

myText.text = myNewText;
myText.onRelease = function() {
   getURL(myNewLink);
}

要调用一个函数我会使用这样的函数:

// AS2  code   
myText.onRelease = function() {
      ExternalInterface.call("my_function()");
   }

//JS function
function my_function() {
   alert("This function is called from ActionScript!");
}

1 个答案:

答案 0 :(得分:0)

谷歌搜索后很多我有&它运作良好:)

JS中的

 function myNewText() {
        return "Click to Goto - StackOverFlow.Com";
    }
function myNewLink(){
return "http://www.stackoverflow.com";
}
AS2中的

myText.onSelfEvent = function (){
    import flash.external.ExternalInterface;
    var ytext:String;
    ytext = String(ExternalInterface.call("myNewText"));
    tstate.text = ytext;
}
myText.onpress = function (){
//    import flash.external.ExternalInterface;
    var yurl:String;
    yurl = String(ExternalInterface.call("myNewLink"));
getURL(yurl);
}