A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] addEventListener problem

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    10

    resolved [RESOLVED] addEventListener problem

    Hi all,
    I have a problem with the event listener on a movieclip that has a dynamic text field. The problem is that in my event listener handler method:
    Code:
    //this works fine 
    this[section]["subsection"+i].addEventListener(MouseEvent.MOUSE_UP,processSubSectionClick);
    ...
    ...
    //this trace gives the instance id of the dynamic text
    function processSubSectionClick(evt:MouseEvent):void{
    	trace("button clicked = "+evt.target.name)
    }
    The true problem is that if I click on the button where the dynamic text is, I get the instance id of the dynamic text, which is not what I want. If i click on the button but not on the text, I get the correct result. Its if as though the text has precedence on the mouse event listener.

    Code:
    Example output:
    
    button clicked = dt_subsectionTitle //wrong: clicked on Dynamic Text
    
    button clicked = subsection0 //correct mc instance id: clicked on button image away from text

    Has anybody seen this before and is there a solution?

    Regards
    Jason

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    You are using the 'MouseEvent.MOUSE_UP'. If you are trying to detect clicks you should use the 'MouseEvent.CLICK'.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Use currentTarget rather than target to get the instance to which the listener was added.

  4. #4
    Junior Member
    Join Date
    Sep 2007
    Posts
    10
    Thank you for your quick response

    I have just changed the MouseEvent.CLICK but I still get the same [incorrect] behaviour

  5. #5
    Junior Member
    Join Date
    Sep 2007
    Posts
    10
    Quote Originally Posted by 5TonsOfFlax View Post
    Use currentTarget rather than target to get the instance to which the listener was added.
    trace("button clicked = "+evt.currentTarget.name)

    This solves the problem. Thanks a lot!!

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The behavior is not incorrect, your code is. The text is the thing you clicked on, so it is the correct target of the event. You need to use currentTarget to get the object currently processing the event.

    Whoops. Posted while you were writing. Oh well. Glad it worked out.

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