2 Replies Latest reply on Jul 17, 2008 5:59 AM by kabunia

    My buttons don't react based on variable values

    Level 1
      Can anyone help me with the following AS code? My question is toward the end of this thread.

      I have a movie clip mcBox1 for which I create an instance, mc_box1, on the stage (main timeline) with a click of a button, btn_openMcBox1 using the following code:

      // Main timeline.
      btn_openMcBox1.onRelease = function():Void
      {
      myMcBox1Tween();
      }

      mc_box1 contains an exit button, btn_Exit1, that removes mc_box1 from the stage (main timeline) once it finishes its exit tween. I use the following code to accomplish this:

      // mc_box1 timeline.
      btn_Exit1.onRelease = function():Void
      {
      _root.myMcBox1Tween.yoyo();
      }

      // Main timeline.
      myMcBox1Tween.onMotionFinished = function():Void
      {
      removeMovieClip(mc_box1);

      }

      mcBox2 is another movie clip for which I create an instance, mc_box2, on the stage (main timeline) with a click of another button, btn_openMcBox2, using similar code as I used above. mc_box2 also has an exit button, btn_Exit2, that removes mc_box2 from the stage (main timeline) after it finished its exit tween.

      I want the exit button, btn_Exit1, in mc_box1 to be disabled when mc_box2 is on the stage because mc_box2 overlaps mc_box1 and hides its exit button, and I want this exit button to be enabled when mc_box2 is removed from the stage.

      I’m using vars, box1Open and box2Open. Here’s a part of my code that checks the variables (main timeline) and based on their value either enables or disables btn_Exit1 in mc_box1.

      // Main timeline.
      var box1Open:Boolean = false
      var box2Open:Boolean = false

      enableExtBtn1 = function():Void
      {
      if(box1Open == true && box2Open == false)
      {
      mc_box1.btn_Exit1.enabled = true;
      }
      }

      disableExtBtn1 = function():Void
      {
      if(box1Open == true && box2Open == true)
      {
      mc_box1.btn_Exit1.enabled = false;
      }
      }

      I run the enableExtBtn1 and disableExtBtn1 functions onRelease of btn_openMcBox1 and btn_openMcBox2 (main timeline) which place mc_box1 and mc_box2 on the stage. I also run the disableExtBtn1 function from mc_box2 timeline onRelease of btn_Exit2 located in mc_box2 using the following code:

      // mc_box2 timeline.
      btn_Exit2.onRelease = function():Void
      {
      _root.disableExtBtn1();
      }

      I’ve created trace() functions that tell me the value of my variables when my movieclips are on/off the stage and they work properly. The code above works only the first time I click either the button that places mc_box1 on stage or the button that places mc_box2 on stage. Once I click btn_Exit2 and remove mc_box2 off the stage, btn_Exit1 in mc_box1 is still disabled, but the variable values change as they should.

      What do you think? Where are my errors?

      Thanks in advance for your time; I really appreciate it!!
        • 1. Re: My buttons don't react based on variable values
          Noelbaland Level 1
          Hello there,

          Is there a myMcBox2Tween function for the btn_openMcBox2 button? If so, why not disable the btn_Exit1 button here

          btn_openMcBox2.onRelease = function():Void
          {
          mc_box1.btn_Exit1.enabled = false;
          myMcBox2Tween();
          }

          Then enable the btn_Exit1 button after the exit tween for the mc_box2 has completed.

          myMcBox2Tween.onMotionFinished = function():Void
          {
          mc_box1.btn_Exit1.enabled = true;
          removeMovieClip(mc_box2);
          }

          That way you don't need to do all that Boolean testing.

          Hope that helps
          • 2. Re: My buttons don't react based on variable values
            Level 1
            Thanks for your response and suggestion Noelbaland. While your suggestion offers a good solution, I would have to write so much more code if I don't use variables given the amount of movieclips that I'm working with. In my original thread I only included sample code, but in reality, I'm using 10 or so menus (mcBox1-10) on the left side of the stage, each with its own exit button that must be disabled when overlapped by any of the additional 10 or so menus (mcBox11-20) on the right side of the stage. Keep in mind that if I place an instance of any of the mc's (1-10) on the left of the stage and an instance of any of the mc's (11-20) on the right on the stage, the exit button for any of the mc's on the left of the stage will need to be disabled, so to give you a scenario of how much code I'd have to write without using variables:

            - mcBox11-20 overlap any of the mcBox1-10 when they're on the stage, so...
            - if mcBox11 is open, my code for the button that opens mcBox11 will have to disable the exit buttons for mcBox1- 10 depending on which one is open, so...
            - if mcBox11 is open -> disable btn_Ext1, disable btn_Ext2, disable btn_Ext3, ..., disable btn_Ext10
            - if mcBox12 is open -> disable btn_Ext1, disable btn_Ext2, disable btn_Ext4, ..., disable btn_Ext10
            - if mcBox13 is open -> disable btn_Ext1, disable btn_Ext2, disable btn_Ext4, ..., disable btn_Ext10
            - and so on...; I'd have to write just as much code to enable these buttons as well.

            If I use variables, I'm creating only two functions (1 to enable and 1 to disable) the exit buttons, no matter which movieclips are placed on stage, and I run these functions on the buttons that open mc's 1-10 and mc's 11-20 (main timeline) and on the buttons that close mc's 11-20 (mc's 11-20 timelines); the code is much shorter this way, except that it's not working as I want it to right now :).

            Sorry for the long email, but I think it's necessary to give you the entire picture.

            Thanks again for your suggestion, and let me know if this makes more sense and if you can offer another suggestion.