A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 - finding out which movie was clicked?

  1. #1

    AS3 - finding out which movie was clicked?

    Okay, I'm starting from scratch learning AS3, so bear with me.

    Let's assume that I've got 3 instances of a movie, each labeled team1, team2, team3. In this movie is a BUTTON (named buttonTest) and a TEXTFIELD(teamReply).

    I'd like to write a function in the root that the event listener from the button within the movie would call on, but how do I find out 'which button' was pressed dynamically in order to send a line of text back?

    For example: if the team2.buttonTest button was CLICKed, how do I pass that information onto the function to tell the function to send the text BACK to that same movie?

  2. #2
    Member
    Join Date
    Oct 2006
    Posts
    79
    Something like this?

    Code:
    buttonName1.addEventListener(MouseEvent.CLICK, buttonPressed);
    
    buttonName2.addEventListener(MouseEvent.CLICK, buttonPressed);
    
    function buttonPressed(event:MouseEvent):void {
             switch(event.target){
                      case buttonName1 :
                      textFieldName.text = "button 1 pressed";
                      break;
    
                      case buttonName2 :
                      textFieldName.text = "button 2 pressed";
                      break;
             }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center