Global Prob

If I declare a global variable on the main stage (_global.sport = "tester";), shouldn't I be able to access this on any movie loaded onto this stage?  I want to have an input box within another movie display the result of the sport variable. I set the var on the properties menu to sport, but it doesn't appear within the input box when the movie is loaded. Why? Also, is there anyway to make all variables within a movie global without having to declare each one.
DocjaymanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

blue-genieCommented:
hi, for some odd reason, when you use the var option, it doesn't show up

do this instead

inputboxname.text = sport

blu.
0
BuffonCommented:
about _global, you should be able to access this variable from anywhere. If you can upload you flash, I'll check it out. Making all the variables _global without declaring them, I dont think its possible.
0
DocjaymanAuthor Commented:
The weird thing is that (var sport = "TEster";) works, but (_global.sport = "tester";) does not work.  I can't even get the global variable to show up in a text field within the same movie.  Maybe I am missing something.  I don't have to have anything special set within the document for _global variables to work do I?  Where would I upload the file to?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

blue-genieCommented:
have u done what i said about setting the .text property to the global rather than using the var option?


i.e use the instance name of the textfield.

I don't know if its documented but that problem does exist.
0
DocjaymanAuthor Commented:
The text field thing worked but I was really just using that to test to see if the variable was passed to the next movie.
I have 2 movies located on the stage and one movie that is a loaded in swf.

On the stage I declared the global variable -  _global.sport = "";

In the first movie I change that variable-
function getthevalue(){
      sport = (sports.getValue());
}

In the second movie I ask this question-
if(sport == "baseball") {
            loadMovieNum("baseballform.swf", 1);
      }

Do you see any reason why this wouldn't work because it won't work for me?
0
blue-genieCommented:
ok, which part doesnt' work. And how are you loading the movies? Are u using loadMovie?

When you say you have 2 movies located on the stage - what exactly do u mean?Are you referring to movieclips, or swfs that have been loaded?

Let's go through a step by step debug process.

1. where are you calling your getthevalue function?
2. have you tried tracing (sports.getValue()) to see that it returns the correct data. (i'm guessing u're using a combobox)
3. the logical sequence of your code is wrong. when and how does your second movie "ask the question" - remember, the function must run first before it can "ask".

do you understand what i mean?
blu.
ps. i just made a mock up and it works fine, your movie set up is wrong. i need to to be more specific about where what is, if possible , upload ur file.







0
DocjaymanAuthor Commented:
The getthevalue function works. The second movie asks the question after a button is pushed.  Also, the first two movies are movie clips located on the main stage  The loadmovienum also works outside of the 'if' statement.  I have never uploaded a file on this site could you please explain where and how I upload the movie?  
0
trigger-happyCommented:
Hello Docjayman,
        There is something you should know about global variables (just in case you didn't know). From what i've seen so far, you are trying to do this: sport = (sports.getValue()); if the sport variable is the global variable, you should always use:
_global.sport = (sports.getValue());

        The value of the global variable can be refereced by just saying sport, but if you want to set the variable, you have to use _globa.sport

--trigger-happy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blue-genieCommented:
no trigger happy, thats not true.

the only time you need to specify _global. before the variablename is when you have a local variable of the same name,
which is not the case here.

0
blue-genieCommented:
oh, i mean post it somewhere on a free server - dont' you have space somewhere? EE itself doesnt' have that facility.

alternatively mail to blue-genie (At) bigfoot.com

and i'll see if i can spot the error and post it here.

blu.
0
trigger-happyCommented:
oh ok, i guess i read some wrong things over the internet, sorry

--trigger-happy
0
blue-genieCommented:
t-h, you're not wrong, its just laziness I guess to omit the _global prefix.

I'm sure many ppl would consider it good practice to include it all the time, but its not a have to.

0
trigger-happyCommented:
true, i add the _global prefix all the time (this is what happens when you use namespaes a lot in C++ XD)
0
DocjaymanAuthor Commented:
I sent it off to you blue-genie
0
blue-genieCommented:
trigger-happy, I HUMBLY apologise.

Docjayman, and to everyone else who might be following this thread, i WAS WRONG!!!!

t-h - i put the _global prefix on the value assignment like you said and it does the trick.

so doc, there's your solution with t-h.

_global.sport = (sports.getValue()); //as th says

my mistake was i was doing it from the same scope, rather than from a movieclip.

ps. doc, just adjust your if statement to Baseball (with an upper case B as well).

so trigger, the intenet didn't lie to you.

blu.
0
trigger-happyCommented:
Yey! guess the internet still helps :)

--trigger-happy
0
blue-genieCommented:
i learned something at least in the process.

quote from "Flash MX 2004 demystified"

"global variables are accessible from every timeline and every scope unless a local variable is defined with the same name as a global variable. In that case, the local variable is used instead of the global variable for the duration of the method. global variables are defined with the _global indentifier and referenced as though they are local."

comfusing?.....

\
0
trigger-happyCommented:
Hey! we've got the same book.....though i haven't read much of it yet since i learn from the internet.....
0
blue-genieCommented:
personally, i found it rather useless, however, Colin Moock's are great ....

:-)

0
trigger-happyCommented:
I'd rather use the internet :) (sorry if the post is starting to get senseless...it happens a lot to every forum i've been to when i'm participating in it....)
0
DocjaymanAuthor Commented:
Okay, that works guys.  So, does this mean that if I declare all of my input boxes in my 1st two movie clips as global variables, in the 3rd loaded movie I can use the ( getURL("athletedatain.cfm", "", "post"); ) statement and all the variables will be posted, or do I have to make another adjustment somewhere?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.