3 Replies Latest reply: Nov 4, 2014 6:20 AM by navigator81 RSS

    Need to Disable to Button Until all the Elements of Array has been Displayed

    navigator81 Community Member

      Hi,

      I have been getting alot of help from this Forum, thought of getting more out of it.I am very New to AS3 and trying my best to get as much as i can but still have some problems coming through.

       

      I am trying to Disable the Button on a Specific Frame until all the Movie Clips in an Array are bieng Displayed , otherwise it should show another movie clip displying the message that all Movie Clips are not Displayed.

       

      Here is the Scenario -

      SUMMARY ///////

      There are three Buttons on the Stage , Button for Next Frame , Button to Load 1st Movie Clip (note1), Button to load Second Movie Clip(note2)

      I am counting the Movie Clips with Array Length (i am not sure if i am doing it right) but the idea is that once all the movie clips are loaded , Button for Next Frame should be enabled otherwise it should stay inactive, rather would display another movie clip as notice that All Movie Clips are not loaded)

       

       

      Here is my Code.

       

      import flash.events.MouseEvent;

      btnnxt.mouseEnabled = false;

      var note1:Mc_Notice1 = new Mc_Notice1;

      var note2:Mc_Notice2 = new Mc_Notice2;

       

       

      function next(Event:MouseEvent):void

      {

        if(count.length == 2)

        {

        btnnxt.mouseEnabled = true;

        nextFrame();

        trace("mouse is Enabled");

        }

        else{

        btnnxt.mouseEnabled = false;

       

       

        }

       

      }

       

      var notes:Array = [note1,note2,note3];

      var count:Array = new Array();

       

       

      btnnxt.addEventListener(MouseEvent.CLICK , next);

       

       

       

       

       

       

      btnload1.addEventListener(MouseEvent.CLICK , load1);

      btnload2.addEventListener(MouseEvent.CLICK , load2);

       

       

       

       

      function load1(Event:MouseEvent):void

      {

       

       

        addChild(notes[0]);

        notes[0].x = 100;

        notes[0].y = 100;

        count.push(1);

        trace ("Count" + count.length);

        }

       

      function load2(Event:MouseEvent):void{

       

       

        addChild(notes[1]);

        notes[0].x = 100;

        notes[0].y = 100;

        count.push(1);

        trace (count);

        //count0 = 1;

        trace (count.length);

        }

       

      Please help in fixing this Error as i am not getting required results.

       

      Please help.

       

      Best Regards

        • 1. Re: Need to Disable to Button Until all the Elements of Array has been Displayed
          Ned Murphy CommunityMVP

          Part of the problem will be that you are trying to rely on clicking a disabled button to enable that button.  As long as the button is disabled you can't use it to enable itself.  Instead of adding an event listener to btnnxt right away, just assign it when it is ready to be used.  Each time you load you need to check the count value and if it equals 2 then you can assign the event listener to enable the btnnxt.

           

          You do not need an array (count) for this since you are only using its length property... a simple integer value will suffice.

           

          Since I do not see you creating a variable named note3, you probably get an error for that.

           

          In your load2 function you are still targeting the note1 for placement where it should already have been placed.

          • 2. Re: Need to Disable to Button Until all the Elements of Array has been Displayed
            navigator81 Community Member

            Thank you so Much Ned for a quick Reply.I am very new to AS3 and therefore having my troubled along with me.

             

            I see the logic in your point which would certainly work but i am trying different ways to achieve it , please forgive my lack of knowledge in this domain , but i am not able to figure out the code for this.

             

            Here is my modification as per your suggestion :But i must be doing something really wrong as its not working

             

            import flash.events.MouseEvent;

            var note1:Mc_Notice1 = new Mc_Notice1;

            var note2:Mc_Notice2 = new Mc_Notice2;

            var notes:Array = [note1,note2];

            var count:int;

            count = 0;

             

             

             

             

             

             

            btnload1.addEventListener(MouseEvent.CLICK , load1);

            btnload2.addEventListener(MouseEvent.CLICK , load2);

             

             

             

             

            function load1(Event:MouseEvent):void

            {

             

             

             

             

              addChild(notes[0]);

              notes[0].x = 100;

              notes[0].y = 100;

              count ++;

              if ( count < 2){

              btnnxt.addEventListener(MouseEvent.CLICK , nextdis);

              }

              trace("Counter Value:" + count);

              }

             

            function load2(Event:MouseEvent):void{

             

             

             

             

              addChild(notes[1]);

              notes[0].x = 100;

              notes[0].y = 100;

              count ++;

              trace("Counter Value:" + count);

              if ( count == 2){

              btnnxt.addEventListener(MouseEvent.CLICK , nextframe);

              }

             

             

             

              //count0 = 1;

              trace("Counter Value:" + count);

              }

             

             

            function nextdis(Event:MouseEvent):void{

              btnnxt.mouseEnabled = false;

            }

             

             

            function nextframe(Event:MouseEvent):void{

              btnnxt.mouseEnabled = true;

              nextFrame();

            }

            • 3. Re: Need to Disable to Button Until all the Elements of Array has been Displayed
              navigator81 Community Member

              Ok , Ned , well your Guidance really worked , thanks alot for that.

               

              I made it work , though since i am very new to AS3 , i really had to experiment , here is the final Code :

               

              import flash.events.MouseEvent;

              stop();

               

               

              var note1:Mc_Notice1 = new Mc_Notice1;

              var note2:Mc_Notice2 = new Mc_Notice2;

              var notes:Array = [note1,note2];

              //var count:Array = new Array(1);

              var count:int;

              count = 0;

               

               

               

               

               

               

              btnload1.addEventListener(MouseEvent.CLICK , load1);

              btnload2.addEventListener(MouseEvent.CLICK , load2);

               

               

               

               

              function load1(Event:MouseEvent):void

              {

               

               

               

               

                addChild(notes[0]);

                notes[0].x = 100;

                notes[0].y = 100;

                count ++;

                trace("Counter Value:" + count);

                if ( count == 2)

                {

               

                btnnxt.addEventListener(MouseEvent.CLICK , nextframe);

               

                }

               

               

              }

               

              function load2(Event:MouseEvent):void

               

                {

               

               

               

               

                addChild(notes[1]);

                notes[1].x = 100;

                notes[1].y = 100;

                count ++;

                if ( count == 2)

                {

               

                btnnxt.addEventListener(MouseEvent.CLICK , nextframe);

               

                }

               

               

                trace("Counter Value:" + count);

                }

               

               

               

               

               

               

               

              function nextframe(Event:MouseEvent):void{

                trace("Mouse Enabled");

                nextFrame();

              }

               

               

              Once again , Thanks alot for the help and Guidance

               

              Best Regards