Skip navigation
Currently Being Moderated

Button Behaviours Not Responding, need help.

Sep 5, 2012 7:38 AM

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");

}

 
Replies
  • Currently Being Moderated
    Sep 5, 2012 8:00 AM   in reply to POWERPLAY27

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 4:50 AM   in reply to POWERPLAY27

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 6:34 AM   in reply to POWERPLAY27

    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?"

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 7:35 AM   in reply to POWERPLAY27

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 9:13 AM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 7, 2012 11:48 AM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 7, 2012 1:05 PM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 7, 2012 6:01 PM   in reply to POWERPLAY27

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

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2012 4:33 AM   in reply to POWERPLAY27

    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".

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2012 10:08 AM   in reply to POWERPLAY27

    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");

                        }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2012 11:50 AM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 9, 2012 5:24 AM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 9, 2012 10:18 AM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 9, 2012 1:26 PM   in reply to POWERPLAY27

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 9, 2012 4:19 PM   in reply to POWERPLAY27

    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");
    }
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 9, 2012 5:40 PM   in reply to POWERPLAY27

    Good Luck

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points