18 Replies Latest reply on Dec 14, 2011 9:53 AM by armandix

    Change a variable by button

    armandix

      I need to change one variable at the click of a button

      the problem is that when I enter the first frame i declared a _global var

      _global.conteudo =null;

       

      In the second frame:

      this equal a _global to :

      _global.conteudo = "enterprise.swf";

       

      But  when I click a button , i need change my _global var  for example:

       

      on (release){

      _global.conteudo="my variable declared";

      }


        • 1. Re: Change a variable by button
          Ned Murphy Adobe Community Professional & MVP

          Keep all your code in the timeline.  Assign instance names to your buttons and assign their code to them in the timeline.  Unless you have other reasons, there should be no need to decalre the variable as _global

           

          btnName.onRelease = function(){

             contuedo = "whatever";

          }

          1 person found this helpful
          • 2. Re: Change a variable by button
            armandix Level 1

            Hello Ned,

            Yes my reasons are because I need to work with external swf and this "conteudo"

            will be read in external swf

            • 3. Re: Change a variable by button
              Ned Murphy Adobe Community Professional & MVP

              You do not need to have it _global, but you can if you prefer.  Still, you should get away from placing code on objects and start keeping it in the timeline.  This makes maintining the scope of variables much easier and it keeps your code where it is easier to find.

               

              Are you having a problem getting a button to change the value of your _global variable?

              • 4. Re: Change a variable by button
                armandix Level 1

                yes Ned I have that problem,

                I can not change the variable var

                • 5. Re: Change a variable by button
                  Ned Murphy Adobe Community Professional & MVP

                  If you are using a _global variable, then there should not be any use of the word "var" in your code with respect to that variable.  The code in your loaded file that you show should change the value of the _global variable in the parent file.  What code are you using to load the external file?

                  • 6. Re: Change a variable by button
                    armandix Level 1

                    hi Ned

                     

                    In the first frame I have :

                    _global.content = null;

                    Second frame :

                    on EnterFrame(Load){

                    _global.content="enterprise.swf";

                    }

                     

                    loadMovie(_global.content,  this);

                     

                    when i call by button I have  this action

                    on (release){

                    _global.content="whatever.swf";

                    }

                    • 7. Re: Change a variable by button
                      Ned Murphy Adobe Community Professional & MVP

                      You do not want to use onEnterFrame, just assign the variable...

                       

                      _global.content="enterprise.swf";

                      loadMovie(_global.content,  this);

                       

                      onEnterFrame does not do what its name implies.  What it does is continuously execute at the frame rate of your file.

                       

                      By loading your external file into "this", you are effectively removing the content of the file that you started with.  The value of the content variable should still change to what your button says it should.   How can you tell that the value has not changed?   What is the purpose of changing the content variable in the external file anyways?

                      • 8. Re: Change a variable by button
                        armandix Level 1

                        I try this

                        global.content="enterprise.swf";

                        loadMovie(_global.content,  this);

                         

                        and onRelease do not change the global var.

                        • 9. Re: Change a variable by button
                          Ned Murphy Adobe Community Professional & MVP

                          How are you determining that the _global variable is not changed?

                          • 10. Re: Change a variable by button
                            armandix Level 1

                            in the frame where I declare the variable, I have a trace (_global.content);

                            • 11. Re: Change a variable by button
                              Ned Murphy Adobe Community Professional & MVP

                              What does it trace?  That trace will have been used up when the variable is declared, so how is it called again?  IF you declare it with a null value, and that trace is in that same frame, then I would expect to see the null value being traced.

                              • 12. Re: Change a variable by button
                                armandix Level 1

                                I declare in the first frame:


                                _global.content =null;

                                 

                                in the second frame I have:


                                _global.content = "empresa.swf";

                                loadMovie(_global.conteudo, this.content_m);


                                Now inside a movie clip have a menu where each item I write:

                                 

                                 

                                corrent_item.onRelease  = function(){

                                                                                                      _root.content_m.swf.gotoAndPlay("auto_1");

                                                                                                      _root._global.conteudo ="selector.swf";

                                                                                                      CloseSubmenus();

                                 

                                 

                                 

                                                                                            }

                                 

                                • 13. Re: Change a variable by button
                                  Ned Murphy Adobe Community Professional & MVP

                                  That is a confused explanation (content is not conteudo) and still doesn't answer what asked regarding your trace.  The last bit of code you show seems to have nothing to do with the _global.content variable.

                                   

                                  You do not need to preface a _global variable with a _root reference either.

                                  • 14. Re: Change a variable by button
                                    armandix Level 1

                                    sorry

                                                                                                          _root.content_m.swf.gotoAndPlay("a uto_1");

                                                                                                         _global.content ="selector.swf";

                                                                                                          CloseSubmenus();

                                     

                                    I have tried  all

                                    • 15. Re: Change a variable by button
                                      Ned Murphy Adobe Community Professional & MVP

                                      You still aren't explaining what a trace in frame 1 has to do with the loaded files changing the _global.content value, nor have you indicated what the value is that gets traced that you say is not what it should be.

                                      • 16. Re: Change a variable by button
                                        armandix Level 1

                                        Ned first frame in the trace is "null" then gets locked in entreprise.
                                        When I release any other item button does not change the variable

                                        I just wonder, how can I do to every time I have declared a variable, change its value through abutton.

                                        .

                                        • 17. Re: Change a variable by button
                                          Ned Murphy Adobe Community Professional & MVP

                                          Are you using a larger font to yell at me - do you think I cannot see what you are writing?  After asking 4 times, you still have not answered my questions regarding the how you determine the value is not chamged, so I will stop trying to help after the following...  If you are going back to the first frame you are resetting the variable to null because of your code there.  If you do not want to reset it to null there then do not aqssign it a null value there, just declare it.

                                          • 18. Re: Change a variable by button
                                            armandix Level 1

                                            I'm not yelling at you just use glasses and without them I had was to increase the font to see.excuse