?
Solved

Global Prob

Posted on 2004-11-09
21
Medium Priority
?
184 Views
Last Modified: 2010-04-03
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.
0
Comment
Question by:Docjayman
  • 9
  • 6
  • 5
  • +1
21 Comments
 
LVL 39

Expert Comment

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

do this instead

inputboxname.text = sport

blu.
0
 
LVL 11

Expert Comment

by:Buffon
ID: 12541893
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
 

Author Comment

by:Docjayman
ID: 12541952
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:blue-genie
ID: 12542061
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
 

Author Comment

by:Docjayman
ID: 12542196
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 12542270
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
 

Author Comment

by:Docjayman
ID: 12542335
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
 
LVL 14

Accepted Solution

by:
trigger-happy earned 375 total points
ID: 12542456
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 12542479
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 12542505
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
 
LVL 14

Expert Comment

by:trigger-happy
ID: 12542510
oh ok, i guess i read some wrong things over the internet, sorry

--trigger-happy
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12542526
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
 
LVL 14

Expert Comment

by:trigger-happy
ID: 12542561
true, i add the _global prefix all the time (this is what happens when you use namespaes a lot in C++ XD)
0
 

Author Comment

by:Docjayman
ID: 12542866
I sent it off to you blue-genie
0
 
LVL 39

Assisted Solution

by:blue-genie
blue-genie earned 225 total points
ID: 12543489
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
 
LVL 14

Expert Comment

by:trigger-happy
ID: 12543511
Yey! guess the internet still helps :)

--trigger-happy
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12543556
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
 
LVL 14

Expert Comment

by:trigger-happy
ID: 12544070
Hey! we've got the same book.....though i haven't read much of it yet since i learn from the internet.....
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12544104
personally, i found it rather useless, however, Colin Moock's are great ....

:-)

0
 
LVL 14

Expert Comment

by:trigger-happy
ID: 12544122
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
 

Author Comment

by:Docjayman
ID: 12547189
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question