0
votes

I'm working on a project that has multiple clickable objects on the stage.

However, when I create the following function, I getting the last defined eventlistener .

// Event listeners
antwoordBox1.addEventListener(MouseEvent.CLICK, antwoordboxclick);
antwoordBox2.addEventListener(MouseEvent.CLICK, antwoordboxclick);

function antwoordboxclick(event:MouseEvent):void {

    trace (event.currentTarget.name); // traces 'antwoordBox2' , whether I click any of the buttons.

    if (event.currentTarget.name == 'antwoordBox1') {

         trace('antwoordBox1 selected');

    }

    if (event.currentTarget.name == 'antwoordBox2')  {

        trace('antwoordBox2 selected');
    }

    currentQuestion++; // function to handle after above

    trekNieuweVraag(); // another function to handle after above
}
// end of my code

Whatever I try, I don't get it fixed. When I use event.target , I get the child movieclip name inside antwoordBox2 (or antwoordBox1) .

Hope anyone can help me! :)

1
Try to verify if your antwoordBox2 is not over antwoordBox1. - akmozo
subdan's solution works @akmozo, many thanks for thinking with me. - 0611nl

1 Answers

0
votes
  1. Disable mouse interaction with children of antwoordBox's:

    antwoordBox1.mouseChildren = false;
    antwoordBox2.mouseChildren = false;
    
  2. Register event listener:

    addEventListener(MouseEvent.CLICK, antwoordboxclick);
    
  3. Inside the event handler:

    if (event.target == antwoordBox1)
        trace('antwoordBox1 selected');
    else if (event.target == antwoordBox2)
        trace('antwoordBox2 selected');