6 Replies Latest reply on Nov 7, 2009 8:45 AM by Matt_Quay_Design

    Button pressed true or false?


      Hi everyone, i need yet more help with my project.


      Basically what i have is three buttons which can be pressed in a maximum of 7 different combinations. Each of these buttons has a movieclip underneath that advances to the next frame when the button is pressed. Each clip has two frames with actions,  frame 1 has:




      var option1:Boolean = false;


      and then frame 2 has:




      var option1:Boolean = true;


      So when you press a button you have true, and false when the button is pushed again.


      i already have a constant loop between frames 2 and 4. At frame 4 i think i need to have some code that detects which state the 3 boolean statements are in and then load a movie depending on which statements are true and which are false.


      How do i go about writing this?


      Many Thanks



        • 1. Re: Button pressed true or false?
          Ned Murphy Adobe Community Professional & MVP

          Basically you'll need a string of conditionals that could probably be written a couple of ways, but in the end the same seven combinations would be separately checked for.  Since they are boolean values you don't need to explicitly ask if they are true or false, just use their values...


          if(option1 && !option2 && !option3){

               // load for option1 true only

          } else if(!option1 && option2 && !option3){

               // load for option 2 only

          } else if (etc.....

          • 2. Re: Button pressed true or false?
            Matt_Quay_Design Level 1

            I tried adding the code at both the start and end frame of the loop but doesnt seem to be working. My code now looks like this:


            I have only used one condition to be checked so far to test the script.


            if(option1 && !option2 && !option3){



            var loader:MovieClipLoader = new MovieClipLoader();





            //Create preloader object

            preload2 = new Object();


                preload2.onLoadStart = function(targetMC) {

            trace("started loading "+targetMC);

            bar2._visible = true;

            pText2._visible = true;

            Option1_MC._visible = false;

            please_wait._visible = true;


            preload2.onLoadProgress = function(targetMC, lBytes, tBytes) {

            bar2._width = (lBytes/tBytes)*100;

            pText2.text = "% "+Math.round((lBytes/tBytes)*100);


            preload2.onLoadComplete = function(targetMC) {


            Option1_MC._visible = true;

            bar2._visible = false;

            pText2._visible = false;

            please_wait._visible = false;

            trace(targetMC+" finished");



            //End Preloader Object


                //Sets the start of loaded movieclip to sync with the current position

            //of the main.clip timeline

            var loadListener:Object = new Object();



            loadListener.onLoadComplete = function() {









            Any ideas?


            Many thanks



            • 3. Re: Button pressed true or false?
              Ned Murphy Adobe Community Professional & MVP

              It is likely something to do with the way you have your timeline setup and coded.  I can't determine how that setup might be from anything you've shown or explained yet.


              One thing that might make things easier to manage... It looks like you plan to pile up a whole bunch of code within each conditional.  You will be better off minimizing the work your conditionals do, both for design sake and for getting things working... let the conditionals make a decision and then send that decision to a function that processes it.  In this case the decision would probably be which swf file gets loaded. The function that you call after the decision is made will deal with the loading activity.

              • 4. Re: Button pressed true or false?
                Matt_Quay_Design Level 1

                Hi Ned,


                I have included the source file for this project so you can see where i'm coming from, hopefully you can shed some light on whats going wrong?

                I have'nt included all the external files to keep file size down so its only the black options that work.


                Many Thanks



                • 5. Re: Button pressed true or false?
                  Ned Murphy Adobe Community Professional & MVP

                  From what I saw, the file will continually cycle and hit the fourth frame where the conditional kicks in.  I saw your conditional on the fourth frame, but I cannot locate the option variables anywhere else in that timeline, so as far as I can tell they are undefined.  But if I run the file and trace the 3 options they come up as what appear to be objects, not boolean values.


                  _level0.option1 _level0.option2 _level0.option3


                  So you may have a namespace issue going on if you intend to use those names for objects and for variables.


                  The bottom line for that conditional is that it needs to evaluate whatever boolean values some variables are assigned. Those variable will best be defined in the main timeline so that the conditional test can see them directly (rename them to not conflict with whatever objects have those names already).  And whatever buttons do the changing of those values need to change the values in the main timeline... example: rename your options to be option1Selected, option2Selected, etc... and have those declared in the main timeline.  Then, have whatever buttons set those value use... _root.option1Selected = ...., etc

                  • 6. Re: Button pressed true or false?
                    Matt_Quay_Design Level 1

                    Hi Ned,


                    I have the conditional test working now. The only problem is that because of the loop between fames 3 & 4 every time the playhead reaches frame 4 with the conditional test it executes the script in correct condition meaning that the code is repeated again and again. How do get the code in the correct condition to execute only once?


                    Many Thanks