AS2 - Get javascript variable value

561 Views Asked by At

I want to get JavaScript variable value to AS2 in simple.

JavaScript

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

How to get vars values in AS2 like this?

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

To call a Function I use some like this:

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

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

There are 1 best solutions below

0
I Follow Mohamed On BEST ANSWER

after googling alot i have that & it works good :)

in JS

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

in 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);
}