37 Replies Latest reply: Sep 11, 2012 2:19 PM by POWERPLAY27 RSS

    Button Behaviours Not Responding, need help.

    POWERPLAY27 Community Member

      I have created buttons in flash, and when a user selects my services button, there is a submenu that appears and within that sub menu there are two other buttons. 

       

      I have named (instance name)one of my buttons in that submenu "design_btn" and have included code to accommodate for all buttons, however when I test the movie I get an error for my submenu "design_btn" with the description of:

       

      "Access of unidentified design_btn.addEventListener(MouseClick Event, designClick);"

       

      I'm confused, because I made sure I have the correct instance name for each of my buttons, yet this one button doesn't correspond.

       

      Any ideas of what the issue is?

       

       

       

       

      This is the code I've used for all my buttons. stop() at the very top

       

      design_btn.addEventListener(MouseEvent.CLICK, designClick);

      function designClick(event:MouseEvent):void

      {

      var request = new URLRequest("http://www.youtube.com");

      navigateToURL(request,"_blank");

      }

        • 1. Re: Button Behaviours Not Responding, need help.
          Ned Murphy CommunityMVP

          design_btn.addEventListener(MouseClick Event, designClick); is what the message shows.

           

          design_btn.addEventListener(MouseEvent.CLICK, designClick); is what your code shows.

           

          First confirm that your code looks like what you posted and not what the error shows.

           

          If that looks well enough, what is the complete error message you are getting?  Where is that button relative to the code, same frame/timeline?

          • 2. Re: Button Behaviours Not Responding, need help.
            POWERPLAY27 Community Member

            yes sorry Ned I mistyped it, it shows the corrected error message you posted.

             

            Once the mouse is over my 'services' button, I have inserted two buttons inside it(symbol editor).

            That works, two buttons show, however the changes I made inside those buttons don't appear to be working. The changes I made inside the symbol editor of the two buttons was for the color to change to blue (instead of red), (Over, Down, Hit).

             

            I presume its got something to do with the error.

            • 3. Re: Button Behaviours Not Responding, need help.
              POWERPLAY27 Community Member

              Anyone else who can help me with this issue as well?

              • 4. Re: Button Behaviours Not Responding, need help.
                Ned Murphy CommunityMVP

                You haven't finished replying to my response.  If you do, I might be able to offer more help.

                • 5. Re: Button Behaviours Not Responding, need help.
                  POWERPLAY27 Community Member

                  Oh didn't I, I tried, if you read the post below your previous one.

                   

                  Not sure how else to explain it.

                  • 6. Re: Button Behaviours Not Responding, need help.
                    Ned Murphy CommunityMVP

                    See if you can try again... "If that looks well enough, what is the complete error message you are getting?  Where is that button relative to the code, same frame/timeline?"

                    • 7. Re: Button Behaviours Not Responding, need help.
                      POWERPLAY27 Community Member

                      Ok here goes: The button 'design_btn' is within my services button, when a user goes over the 'services' button with the mouse, the submenu buttons appear. The buttons are not visible unless the user touches the mouse over the services button.

                      The code itself is all in one place, in a seperate layer. Any better?

                      • 8. Re: Button Behaviours Not Responding, need help.
                        Ned Murphy CommunityMVP

                        Nope.  You are not answering the questions I am asking.

                        • 9. Re: Button Behaviours Not Responding, need help.
                          POWERPLAY27 Community Member

                          buttonError.jpg

                          Thats the full error message.

                           

                          The code is all in one place in layer 2, my buttons are stationed in layer 1.

                          • 10. Re: Button Behaviours Not Responding, need help.
                            Ned Murphy CommunityMVP

                            What you said earlier doesn't gel with what you just described.  You said the buttons are within your services button, which puts them on another timeline.  So if the code is in the main timeline, and the button is inside some other object, then you have to target it thru that object, as in...

                             

                            services.design_btn.addEventListener... etc.

                             

                            If your services button happens to actually be a SimpleButton symbol, and it is not a MovieClip symbol, then you will not be able to place anything inside of it and be able to target whatever that is, nor will you be able to interact with it... the Services button would be the only thing you interact with.  Button symbols have a very limited set of properties.

                             

                            If your services button is a MovieClip symbol, then the code I just showed should work, but you still could have issues with the services button interfering with interacting with the buttons inside it.  You will be better of making the submenu a separate object.

                            • 11. Re: Button Behaviours Not Responding, need help.
                              POWERPLAY27 Community Member

                              Thanks for your response. Yes my services button is a movie clip. I have 2 keyframes in the symbol editor for up and over. In the over keyframe, I have two other movie clip buttons appearing. I tried to see if I could enter code within the services symbol editor, but this is not possible. When I run the movie, it works up to the point where I place my mouse over the services button, the sub menu buttons (also movie clips)then appear as intended, but when I try to link those buttons to my webpage, I get that error.

                               

                              How would I make the submenu a seperate object, when I would like for the submenu to appear once the mouse is over the services symbol?

                              • 12. Re: Button Behaviours Not Responding, need help.
                                POWERPLAY27 Community Member

                                Does anyone understand what I'm trying to do here and how I can get this working to meet my expectations specified in my post above?

                                • 13. Re: Button Behaviours Not Responding, need help.
                                  Ned Murphy CommunityMVP

                                  Instead of placing the other buttons inside the services button, add them to the same timeline as the services button and control their visible properties with your over/out event listeners. 

                                   

                                  You could leave them inside the services button in frame 1 instead of frame 2, controlling their visiblity.

                                   

                                  If you wanted to retain the frame 2 presence of them for your rollover, you could have them starting in frame one but have code in frame 1 to make the invisible and then make them visible in frame 2.

                                   

                                  If you leave them inside the services button, you will need to use the event.target property to determine which button you are interacting with when you click it.  You only need the services button;s CLICK event listener and handler for that... inside the handler you check to see which button was clicked and take the action needed.

                                  • 14. Re: Button Behaviours Not Responding, need help.
                                    POWERPLAY27 Community Member

                                    Can you give me an example of the event.target property please?

                                    • 15. Re: Button Behaviours Not Responding, need help.
                                      Ned Murphy CommunityMVP

                                      Here's a link to file I made two or three years ago as an example for someone here.  It pretty much demos what you might want to do if you keep the buttons inside the services button...

                                       

                                      http://www.nedwebs.com/AS3_Event_Target.fla

                                       

                                      The larger area you see would be the services button.

                                      • 16. Re: Button Behaviours Not Responding, need help.
                                        POWERPLAY27 Community Member

                                        That link doesn't work.

                                         

                                        This is all too confusing, but I'm sticking with it for the sake of learning this stuff.

                                        How would I go about starting this code? I'm lost.

                                        • 17. Re: Button Behaviours Not Responding, need help.
                                          Ned Murphy CommunityMVP

                                          Dang it... and I visually doublechecked the link... eyes vs brain are going I guess...

                                           

                                          http://www.nedwebs.com/Flash/AS3_Event_Target.fla

                                          • 18. Re: Button Behaviours Not Responding, need help.
                                            POWERPLAY27 Community Member

                                            Thank you Ned , I have ammended my code to correspond with yours, but now I'm getting more errors.

                                             

                                            Errors:

                                            buttonErrorA.jpg

                                             

                                            buttonErrorB.jpg

                                             

                                             

                                             

                                             

                                            Code:

                                             

                                            services_btn.addEventListener(MouseEvent.CLICK, servicesClick);

                                            function servicesClick(event:MouseEvent):void

                                            {

                                                      if(evt.target.name == "webdesign_btn"){

                                                                var request = new URLRequest("http://www.sign.net/");

                                                                navigateToURL(request,"_blank");

                                             

                                                      } else if(evt.target.name == "pcRepair_btn"){

                                                                var request = new URLRequest("http://www.sign.net/");

                                                                navigateToURL(request,"_blank");

                                                      }

                                                      else if(evt.target.name == "busSupport_btn"){

                                                                var request = new URLRequest("http://www.sign.net/");

                                                                navigateToURL(request,"_blank");

                                                                }

                                            }

                                            • 19. Re: Button Behaviours Not Responding, need help.
                                              Ned Murphy CommunityMVP

                                              You have to be careful to avoid falling into the trap of blindly copying code.  What you name the argument in your function declaration needs to stay consistent.  If you name it "event" your code needs to use that...

                                               

                                              function servicesClick(event:MouseEvent):void

                                              {

                                                        if(event.target.name == "webdesign_btn"){

                                               

                                              That "event" is just a variable name, you can use whatever you choose (dog, doghnut, cheese), but most folks use some variation of the word "event", such as "evt" or "e".

                                              • 20. Re: Button Behaviours Not Responding, need help.
                                                POWERPLAY27 Community Member

                                                I'm still getting the second error:

                                                 

                                                buttonErrorB.jpg

                                                 

                                                I'm getting two of these errors for two lines.

                                                • 21. Re: Button Behaviours Not Responding, need help.
                                                  Ned Murphy CommunityMVP

                                                  Either don't name the variable with the same name each time or declare it outside of the function and assign it inside.  The latter version would be...

                                                   

                                                  var request:URLRequest;

                                                   

                                                  function servicesClick(event:MouseEvent):void

                                                  {

                                                            if(evt.target.name == "webdesign_btn"){

                                                                      request = new URLRequest("http://www.sign.net/");

                                                                      navigateToURL(request,"_blank");

                                                   

                                                            } else if(evt.target.name == "pcRepair_btn"){

                                                                      request = new URLRequest("http://www.sign.net/");

                                                                      navigateToURL(request,"_blank");

                                                            }

                                                            else if(evt.target.name == "busSupport_btn"){

                                                                      request = new URLRequest("http://www.sign.net/");

                                                                      navigateToURL(request,"_blank");

                                                                      }

                                                  }

                                                  • 22. Re: Button Behaviours Not Responding, need help.
                                                    POWERPLAY27 Community Member

                                                    Thank you again for your help Ned that seems to get rid of those errors, but now onto another issue

                                                     

                                                    When I click the submenu buttons nothing happens, when I click the main timeline buttons they work, also when I place the mouse over the submenu buttons they won't change to blue like I would like them to.

                                                    For each button in the submenu I changed the background color to blue in the over, down, hit segments. When I run the movie they don't change color when I place the mouse over them.

                                                    • 23. Re: Button Behaviours Not Responding, need help.
                                                      Ned Murphy CommunityMVP

                                                      THat is because they are being blocked by the rollover code of the services button.  As long as you want to have them inside you'll suffer that fate.

                                                       

                                                      What you can try though, is to have code in your services CLICK/MOUSE_OVER/MOUSE_OUT functions that do the things you want still using the event.target to determine which button you want to target.

                                                       

                                                      Give it try yourself first.  I don't like doing people's coding for them (unless I'm getting paid).  Youi can learn more by trying yourself.  Just see how the click function tests to see what button is being interacted with and use that same code structure to tell the buttons to change colors and whatnot.

                                                       

                                                      Do not use ROLLOVER/ROLLOUT event lsisteners if you want to get the event.target working for you.  They will point at the services button.  MOUSE_OVER and MOUSE_OUT are what you'll need to get the event.target you need.

                                                      • 24. Re: Button Behaviours Not Responding, need help.
                                                        POWERPLAY27 Community Member

                                                        You've helped me quite a bit already. I don't expect you to write code for me, just merely point me in the right direction, which you mostly have and I appreciate that.

                                                         

                                                        I actually want to learn for myself and the best way to do that, as you say is to try myself.

                                                        • 25. Re: Button Behaviours Not Responding, need help.
                                                          POWERPLAY27 Community Member

                                                          Within my movieclip button there are two components, one is shape and one is label.

                                                          How would I target the shape to change its color?

                                                           

                                                          I am also wondering about this code I've done, which is logical to me, but not the complier, lol.

                                                           

                                                          services_btn.addEventListener(MouseEvent.MOUSE_OVER, serviceOver);

                                                          //The submenu buttons will only become visible once the mouse cursor is over the button, no clicking is required for this button

                                                           

                                                          //submenu button (one of 4 that appears)

                                                          webdesign_btn.addEventListener(MouseEvent.CLICK, webDesignClick);

                                                          //when this button IS clicked, please direct me to URL.

                                                          function serviceOver(evt:MouseEvent):void

                                                          {

                                                                              function webDesignClick (evt:MouseEvent.CLICK):void{

                                                           

                                                                              var request = new URLRequest("http://www.sign.net/");

                                                                              navigateToURL(request,"_blank");}

                                                           

                                                          (is a function possible within another function? I am getting an error: 1046: Type was not found or was not a compile-time constant: CLICK.)

                                                           

                                                           

                                                          The reason I did this was because the previous code:

                                                           

                                                          function servicesClick(event:MouseEvent):void

                                                          {

                                                                    if(evt.target.name == "webdesign_btn"){

                                                                              request = new URLRequest("http://www.sign.net/");

                                                                              navigateToURL(request,"_blank");

                                                           

                                                          did not work in terms of taking me to the url I specified, yes even without the errors.

                                                          • 26. Re: Button Behaviours Not Responding, need help.
                                                            Ned Murphy CommunityMVP

                                                            To target an object it needs to be an object you can assign an instance name to, and you assign it an instance name and use that name.

                                                             

                                                            You are treating the code like it is the button, one inside the other.  Never nest functions within other functions.

                                                             

                                                            If you read thru all the responses I have given you so far, they cover the errors that you are continuing to make.  All the information you need to do what you want is contained in what's been discussed already.

                                                            • 27. Re: Button Behaviours Not Responding, need help.
                                                              POWERPLAY27 Community Member

                                                              I'm new to AS3 and to programming so can't see it as clearly, sorry for being a pain, I'm trying myself, but the more I try the more confused I get.

                                                              • 28. Re: Button Behaviours Not Responding, need help.
                                                                Ned Murphy CommunityMVP

                                                                If it is any consolation, you are experiencing the same learning pain that every one of us has gone thru... lost sleep, lost hair, lost mind... it's all part of it.

                                                                 

                                                                In one of your last postings you were trying to assign a listner to the button inside the services button.  I already said that won't work because the services button having listeners will block any interaction with the objects inside.

                                                                 

                                                                So you need to make use of what the services listener's event.target can tell you as to which object you are interacting with so that you can take the action you need to take.

                                                                 

                                                                If you want to have a MOUSE_OVER listener for the inner button, you need to make use of the one that the services button already has, because that one is blocking any ability to have one work for you for any button inside.

                                                                • 29. Re: Button Behaviours Not Responding, need help.
                                                                  POWERPLAY27 Community Member

                                                                  Ok, but this code below does not actually say when "webdesign_btn" is clicked goto the specified URL or does it? When I try to click the button nothing happens.

                                                                   

                                                                  var request:URLRequest;

                                                                  services_btn.addEventListener(MouseEvent.MOUSE_OVER, serviceOver);

                                                                  function serviceOver(evt:MouseEvent):void

                                                                  {

                                                                            if(evt.target.name == "webdesign_btn"){

                                                                               request = new URLRequest("http://www.sign.net/");

                                                                               navigateToURL(request,"_blank");

                                                                                        }

                                                                  • 30. Re: Button Behaviours Not Responding, need help.
                                                                    Ned Murphy CommunityMVP

                                                                    No, that code says to go to the url when you MOUSE_OVER the button with the name property webdesign_btn which is inside services. 

                                                                     

                                                                    As I told you earlier, the mouseover function is where you want to deal with the color change or whatever you want to have happen when you rollover one of the buttons. 

                                                                     

                                                                    You should have another listener and event handler function for the CLICK interaction, and even another for the MOUSE_OUT.

                                                                     

                                                                    Maybe you should try getting things working in the example file I gave you first.  MAybe you will see something while doing it that will trigger you to realize what might be different in your design.

                                                                    • 31. Re: Button Behaviours Not Responding, need help.
                                                                      POWERPLAY27 Community Member

                                                                      "You should have another listener and event handler function for the CLICK interaction, and even another for the MOUSE_OUT."

                                                                      For webdesign_btn?

                                                                       

                                                                      so:

                                                                       

                                                                      webdesign_btn.addEventListener(MouseEvent.CLICK, designClick);

                                                                      function designClick(evt:MouseEvent):void

                                                                       

                                                                      {

                                                                                if(evt.target.name == "webdesign_btn"){

                                                                                   request = new URLRequest("http://www.sign.net/");

                                                                                   navigateToURL(request,"_blank");

                                                                                            }

                                                                       

                                                                      or the same thing, but with a click function for service?

                                                                       

                                                                      Sorry I'm still not getting it, my eyes are kind of hurting today as I've spent a lot of time looking at different coding on AS3, and still quite confused.

                                                                      Should I just read a book on AS3 from page to page, I'm actually contemplating it. lol pppfffftttt

                                                                       

                                                                       

                                                                      EDIT 16:00 ok I've done an event listener/handler for both CLICK and MOUSE_OUT for service_btn, with the same code below it, but still nothing happens when I click one of the submenu buttons. Luckily getting no errors, but as well nothing at all happens. lol

                                                                      If I was being taken to the url at least that would have been a step forward and then I could just concerntrate on changing the colo rshape within each submenu movieclip.

                                                                       


                                                                      • 32. Re: Button Behaviours Not Responding, need help.
                                                                        Ned Murphy CommunityMVP

                                                                        I don't think reading any books is going to help you.  I don't mean to offend you, but if you have a hard time understanding what I've explained a few times now, I doubt you'll get anywhere with a book.

                                                                         

                                                                        If you didn't try what I said you should try, you should.  Go back to the file I gave you and work with that.  It is properly set up and coded.  In fact, if you add the following code to it, you can see the rollover and rollout functionality at work as well.

                                                                         

                                                                        MC.addEventListener(MouseEvent.MOUSE_OVER, processMCOver);
                                                                        MC.addEventListener(MouseEvent.MOUSE_OUT, processMCOut);

                                                                         

                                                                        function processMCOver(evt:MouseEvent):void{
                                                                        if(evt.target.name == "btn1"){
                                                                          trace("You are over btn1");
                                                                        } else if(evt.target.name == "btn2"){
                                                                          trace("You are over btn2");
                                                                        }
                                                                        }

                                                                         

                                                                        function processMCOut(evt:MouseEvent):void{
                                                                        if(evt.target.name == "btn1"){
                                                                          trace("You are off btn1");
                                                                        } else if(evt.target.name == "btn2"){
                                                                          trace("You are off btn2");
                                                                        }
                                                                        }

                                                                        • 33. Re: Button Behaviours Not Responding, need help.
                                                                          POWERPLAY27 Community Member

                                                                          I actually now have code that corresponds with your above code's concept, the movie is running without any errors, so there is something that is stopping the buttons from working.

                                                                          To add your code doesn't have what I need mine to have. I need to target the SHAPE! inside the submenu buttons movieclip and to change its color when the mouse rolls over it.

                                                                          • 35. Re: Button Behaviours Not Responding, need help.
                                                                            POWERPLAY27 Community Member

                                                                            Thanks.

                                                                             

                                                                            Still getting nowhere grrrrr.....lol

                                                                             

                                                                            If you feel like inputting something that you feel will help me, please do so at any time.

                                                                            • 36. Re: Button Behaviours Not Responding, need help.
                                                                              POWERPLAY27 Community Member

                                                                              Ned, finally I am one step ahead as opposed to the big round circles I was going around before, I am directed to the site I want to be directed to.


                                                                              Now I need to make the buttons invisble, how would I go about doing that?

                                                                               

                                                                               

                                                                               

                                                                              "Instead of placing the other buttons inside the services button, add them to the same timeline as the services button and control their visible properties with your over/out event listeners. 


                                                                              You could leave them inside the services button in frame 1 instead of frame 2, controlling their visiblity. Decided to use this method you suggested.


                                                                              If you wanted to retain the frame 2 presence of them for your rollover, you could have them starting in frame one but have code in frame 1 to make the invisible and then make them visible in frame 2.


                                                                              If you leave them inside the services button, you will need to use the event.target property to determine which button you are interacting with when you click it.  You only need the services button;s CLICK event listener and handler for that... inside the handler you check to see which button was clicked and take the action needed."

                                                                               

                                                                              Spot on!

                                                                              • 37. Re: Button Behaviours Not Responding, need help.
                                                                                POWERPLAY27 Community Member

                                                                                I have inserted my submenu buttons in a movieclip. I would like that movie clip to be invisible by default, so that when my mouse is on the services button the movieclip then becomes visible.

                                                                                 

                                                                                What is the best way to approach this to get the desired outcome?