10 Replies Latest reply on Aug 8, 2006 7:31 PM by 3fx

    setting _global variable.... (easy?)

    3fx
      Hi There,

      I seem to be having major problem programming in flash... but learning it slowly... OK, here goes. I have a this _global variable called X. We have to detect what X is, then give it another value. Anyone can help? Here is my code that works well at the first time, then it doesn't....

      Can anyone help out???
        • 1. Re: setting _global variable.... (easy?)
          deej07 Level 1
          i think you're "if" code should be on small caps, AS is case sensistive.
          try this one.


          • 2. Re: setting _global variable.... (easy?)
            3fx Level 1
            I made a spelling mistake when typing, so that is not the problem, I checked... It actually works once, then it doesn't....
            • 3. Re: setting _global variable.... (easy?)
              deej07 Level 1
              what exactly you want to do with _global.X after detecting it?
              if you set the _global.X = 0 then press the button it will clearly display 25, and if you press it again, it will display 50, but this time it will be permanently equal to 50. Because your if/else statement is to set _global.X to 50 if it's not equal to 0.

              try this code, so you can see the value of _global.X each time you press the button.

              • 4. Re: setting _global variable.... (easy?)
                3fx Level 1
                It is very complicated to explain what I want to achieve.... The most important thing is to get this sequence correct... As I said it works for the first time, then it doesn't. So, if we set X=25, then X=50, then why the third time doesn't know what it X is? The on (release) will be used more than once (even repeatedly and also in combination with other buttons), hence the importance of X to get many different values ....
                • 5. Re: setting _global variable.... (easy?)
                  Lacrymocéphale Level 1
                  <<then why the third time doesn't know what it X is?>> What are the symptomes to say that ? describe your sequence properly. What do you expect from X when is equal to 50 ? With your current code, it can't change anymore. Are you looking for a simple _global.X+=25 ??
                  • 6. Re: setting _global variable.... (easy?)
                    deej07 Level 1
                    your code works fine with me. I pressed the button a dozen times, and on the first press I received a _global.X value of 25 and on the succeeding the result is always 50. Here's what I see,

                    1) it's either you have your button in an instance where the _global.X is undeclared. Try declaring _global.X on the very first frame of the topmost level of the timeline.

                    2) Or you have declared _global.X more than once. try renaming your _global declarations.
                    • 7. Re: setting _global variable.... (easy?)
                      3fx Level 1
                      Thanks guys. I will explain further.

                      The _global variable is declared on the main timeline. The buttons are deep inside the file.... Now when a button is pressed, it needs to change the actual _global.X, which now it doesn't... It works inside the loop (that is why it worked in my end as well), but not working on _global scale....

                      So to sum up
                      1. Global variable X is declared globally
                      2. Deep inside the timeline, the variable X is called
                      3. Deep inside the timeline, the global variable X is overwritten
                      4. Deep inside the timeline (another location, different parent, child, subchild, etc, ) the same global variable X is called (recently overwritten by our new commands)....

                      So we are looking at solving case 3 and 4...
                      • 8. Re: setting _global variable.... (easy?)
                        3fx Level 1
                        the _global variable X is declared as 0 (in the main timeline), then it changes from 0 to undefined.... Really clueless...
                        • 9. Re: setting _global variable.... (easy?)
                          3fx Level 1
                          the _global variable X is declared as 0 (in the main timeline), then it changes from 0 to undefined.... Really clueless...
                          • 10. Re: setting _global variable.... (easy?)
                            3fx Level 1
                            Hi all thank you for your help, I had integers and strings defined for the _global variable, that is why it didn't work properly. Really appreciate your input