5 Replies Latest reply: Nov 8, 2014 2:43 PM by Ned Murphy RSS

    Applying Different Function to one Button based on which Frame it is

    navigator81 Community Member

      Hi,

      I am working on this Presentation where i have Next and Back Button

      In Normal conditions , Net button would only take the user to the  Next Frame, but in Some Frames , i have certain Popups which has to be loaded before user can move out of that frame.

       

      I am trying to develop that logic to work around same Mouse Event Listener but different function applied when needed.

       

      I am very new to AS3 so any guidance in this matter would be highly appreciated in making this code work.

        • 1. Re: Applying Different Function to one Button based on which Frame it is
          Ned Murphy CommunityMVP

          You could put a conditional or switch in the event handler function that takes action based on the currentFrame property.

          • 2. Re: Applying Different Function to one Button based on which Frame it is
            navigator81 Community Member

            Ned. thats what i am trying to put but for some reasons , its not taking me passed that frame , i have succeeded to stop it on a certain frame by removing the vent Listener but once i am done with the condition , it should reactive the Listener , but thats not happening , i know its a pretty simple thing , but due to my lack of experience with AS3 , its causing me trouble to troubleshoot it all by my self.

             

            Here is my Code:

            btn_nxt.addEventListener(MouseEvent.CLICK, simplenext);

             

            ////////////////////////////////SIMPLENEXT FUNCTION FOR NEXT BUTTON ///////////////////////////////////////////

             

            function simplenext(event: MouseEvent): void
            {

             

             

            if (currentFrame == 9)
            {
            btn_nxt.removeEventListener(MouseEvent.CLICK, simplenext);
            trace("Normal Next Button Disabled");
            btn_nxt.addEventListener(MouseEvent.CLICK, nextframe9);
            trace("Frame 9 Next Button Activated");
            btn_notice1.addEventListener(MouseEvent.CLICK, loadnotice1);
            pop1.closebtn.addEventListener(MouseEvent.CLICK, unloadbtn1);
            }

             

             

            else {

             

             

             

             

            nextFrame();

             

             

            }
            }

             

             

            /////////////////////////FUNCTION FOR FRAME 9 //////////////////////////////////////

             

            Please note that Count is the Counter variable that i defined to increment once the popup movie clip is loaded

             

             

            function nextframe9(event: MouseEvent): void

              {

             

              if(count == 1 && stage.contains(pop1) )

              {

             

              removeChild(pop1);

             

              }

             

              if(count == 1)

              {

              nextFrame();

              }

             

              else

              {

              addChild(pop1);

              pop1.x = 40;

              pop1.y = 120;

              count = 1;

              }

             

             

              }

            • 3. Re: Applying Different Function to one Button based on which Frame it is
              Ned Murphy CommunityMVP

              What I suggested is not what I see you implementing.  You are trying to change the function that the button calls and you don't need to do that, but you can if you work out the logic properly.  Chances are you are missing following the logic if it is not behaving as you intend.  I think you are tangling yourself in the logic by separating things out as you are.

               

              This is where you need to learn how to make the best use of the trace() function.  If you expect something to happen based on conditions being met, then you need to check those conditions to see if they are what you think rthey should be. 

              • 4. Re: Applying Different Function to one Button based on which Frame it is
                navigator81 Community Member

                Thanks Ned for the guidance , can you give me an example a sample to get an idea of how you think I should run this , I am new with action script 3 and you ar eright , I am tangeling my self a lot with this logic for a while now , I need to devliver this presentation by Monday and I am no where near fixing this thing for me.

                • 5. Re: Applying Different Function to one Button based on which Frame it is
                  Ned Murphy CommunityMVP

                  If you find a function is not doing whatyou expect, test the conditions that should have made it process.  For instance... check the values to see that they are what you expect them to be....

                   

                  function nextframe9(event: MouseEvent): void

                    {

                   

                    trace("count value (1?): ", count);

                    trace("pop1 present (true)?: ", stage.contains(pop1));

                   

                    if(count == 1 && stage.contains(pop1) )