user4320654
user4320654

Reputation:

currentTarget.name and gotoAndPlay AS3

I am very new to this and I am trying to combine currentTarget.name and gotoAndPlay which does not work. Can someone please help me, I want to play the symbol I click on, but I can't just write ball1.gotoAndPlay(2);, because there are 3 movieclips. I want to play the one I click on.

ball1.addEventListener(MouseEvent.CLICK, trykkFunksjon);
ball2.addEventListener(MouseEvent.CLICK, trykkFunksjon);
ball3.addEventListener(MouseEvent.CLICK, trykkFunksjon);

function trykkFunksjon(evt)
{
    if (mineTall.length < 7)
    {
        var innTall = evt.currentTarget.name.split("ball");;
        trace(int(innTall[1]));
        mineTall.push(int(innTall[1]));
    }
    else
    {
        txtOutput.text = "Du kan ikke gjette flere tall";
    }
}

Upvotes: 0

Views: 171

Answers (1)

taskinoor
taskinoor

Reputation: 46037

evt.currentTarget will refer to the MovieClip that was clicked. So you can call gotoAndPlay on it directly without getting the name.

(evt.currentTarget as MovieClip).gotoAndPlay(2);

Upvotes: 1

Related Questions