Skip to main content
February 14, 2007
Question

GetVarialbe(); SetVariable(); not working as expected?

  • February 14, 2007
  • 3 replies
  • 459 views
Hello, I'm trying to understand how GetVariable() and SetVariable() work.

I've written the following ActionScript code in the actions frame of the top layer in my .fla:

testVar = "test1";
getVar = GetVariable("testVar");
SetVariable("testVar", "test2");
getVar2 = GetVariable("testVar");

When I walk through this code in the debugger, I don't see the expected behavior:
getVar - remains undefined
testVar - does not get assigned "test2" like I thought it would by calling SetVariable()
getVar2 - remains undefined.

I'm guessing it has something to do with variable scoping or something like that, but I'm not sure what.

Any help?

Thanks in advance.
This topic has been closed for replies.

3 replies

February 15, 2007
I have been having plenty of security issues with my Flash application lately, but SetVariable is not one of them...

If you have one browser with your controlling application and another browser that embeds your Flash movie, it should still be fine, as long as they can talk to each other. I would suggest making sure that the javascript with the SetVariable method is getting the correct value before sending it to Flash. If it is correct, then it should be good to go.
February 14, 2007
GetVariable and SetVariable are calls that you can make from javascript.

See this page: http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html

February 14, 2007
Ok, I understand. Unfortunately, I'm having problems getting Get/Set to work so I was hoping to test them inside ActionScript to test the debugging.

Essentially the issue I'm having is that the SetVariable doesn't seem to stick.

For example, if I call SetVariable() and then immediately call GetVariable() on the same name, it doesn't return the new value. However, GetVariable() works fine on variables I've defined in my ActionScript - so I know at least that much works.

I'm wondering if these calls can only be made on certain types of variables? Does it have to do with the scoping of the variables?

Thanks for your help.
February 14, 2007
As far as I know, only strings can be passed back and forth using GetVariable and SetVariable (search for the Flash / Javascript Integration Kit if you want to pass other data types). Scope is important, as the javascript call must include the path to where the variable is stored in your Flash file.

I haven't tried doing a Set followed immediately by a Get, so I can't comment on your problem. However, I know that if you are using getURL to execute javascript commands from within the Flash, you can't do getURL twice in a row (only one will work). Is this related? I have no idea... but maybe?
Inspiring
February 14, 2007
There are no such methods available.