Variable communication

I am playing around trying to teach myself actionscript and I’m getting frustrated with a simple dynamic textbox. I have a main movie with just one frame and in the frame actionscript I have :

newitemwidth;
totallength = 10 + newitemwidth;

I have a button on this main movie that on release, among other things, has:

newitemwidth = 115;

I have a dynamic textbox on the movie as well with the variable set to:

totallength

When I test the movie, the textbox shows 10, but when I click the button it doesn’t change to 125 with the added newitemwidth. Am I missing some rule about global variables here? Thanks for your help.

BriCar77
brian_carey77@ou.edu

You must take note of where the variable was declared. Supposing that newitemwidth is on the main timeline, you can target it by either using absoluate addressing (_root for example, which is evil :P) or relative addressing (_parent for example). So use _root.newitemwidth on release of the button instead of newitemwidth. If you do not target an exisitng variable, a new one will be created.

Also, you might want to update the textbox. It’s not because you set the textbox to display newitemwidth once, that it’ll display it forever. You’ll also have to update totallength if you’re displaying totalllength. So use this:


on(release){
_root.newitemwidth = 115;
_root.totallength = _root.newitemwidth+10
}

I was thinking that it had to do with updating totallength, but I had no idea it was so simple. Thanks a million! God I love this forum!
BriCar77

No problem =)