Hamzeh
Hamzeh

Reputation: 103

How do I connect AS3.0 to a variable in js?

I've got an AS3 code that I want to assign in JavaScript as a variable like so:

var Name = ;

If I want to set a simple stylesheet I would use:

var Name = { Name.width:500 }

etc.

How do I do that in AS3? i want to do it like so

var As3 = action script code;

i want to give a var to the actionscript so i can use it later

Upvotes: 0

Views: 101

Answers (1)

Jeff Ward
Jeff Ward

Reputation: 19006

A SWF on a webpage can interoperate (call functions, set variables, etc) with JavaScript using ActionScript's ExternalInterface.

For example:

ExternalInterface.call("console.log", "Hello JavaScript world!");

Apparently calling eval only works in some browsers, but you can proxy the eval as noted in this answer.

ExternalInterface.call("eval", "window.foo = 'bar'");

Of course, your CSS example is very malformed... You might could:

ExternalInterface.call("eval", "document.getElementById('myDiv').style.width='50px'");

Google for more examples of using ExternalInterface to set variables, call functions, setup callbakcs, etc.

Upvotes: 2

Related Questions