Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read a global javascript variable from actionscript

Given that there is a global javascript variable on my web page named myVar, how can I access the value of the variable myVar from within my flash movie using javascript?

I see plenty of examples of using external interface in order to execute javascript from actionscript, but I am unable to find examples of returning values back into the flash movie using actionscript.

Thanks in advance. I hope my question is clear enough.

like image 483
Rafe Avatar asked Jan 24 '23 18:01

Rafe


1 Answers

ExternalInterface works by allowing JavaScript to invoke an ActionScript function in the movie, and vice-versa. You can optionally receive a return value back from the invoked function. Here's a very simple example:

JavaScript:

<script language="JavaScript">
    function getMyVar()
    {
        return myVar;
    }
</script>

Flash/AS:

import flash.external.ExternalInterface;
var result:string = ExternalInterface.call("getMyVar");
like image 120
Rex M Avatar answered Feb 20 '23 22:02

Rex M