PDA

View Full Version : i think this might be quite simple... please help me stop a movieclip!



yokiki
July 23rd, 2008, 02:50 PM
Hi everyone,

im very new to AS3 so sorry if this is a basic question!

I made a movie clip which is a turnip - when you click it its leaves grow. (it has a button on top of it as i wanted the mouse curser to change to a hand so the user knows it will do something)

this is the script i used for the button

turnip1.addEventListener(MouseEvent.MOUSE_UP,turni pGrow);
function turnipGrow(event:MouseEvent){
turnip1.play();
}

my probem is that i only want it to happen once then if the user clicks the turnip again nothing happens. at the moment the leaves dissapear and grow again on the second click (and on every click)

its all on one frame.

also... is there a way to make the mouse curser change to the hand without making a button? can it be done with a movie clip?

Thanks very much for any help!

Kira

nortago
July 23rd, 2008, 03:10 PM
you could add a variable in?

so something like this...



var turnipClicked:Boolean = false;

turnip1.addEventListener(MouseEvent.MOUSE_UP,turni pGrow);
function turnipGrow(event:MouseEvent){
if(turnipClicked == false){
turnipClicked = true;
turnip1.play();
} else {
trace("turnip already clicked");
}
}

You could also remove the event listener


turnip1.addEventListener(MouseEvent.MOUSE_UP,turni pGrow);
function turnipGrow(event:MouseEvent){
turnip1.removeEventListener(MouseEvent.MOUSE_UP,tu rni pGrow);
turnip1.play();
}

yokiki
July 23rd, 2008, 03:23 PM
Hi Nortago,

Thanks so much for your help! It works perfectly now - I used the second option you gave me.

I'd been searching online and in books for ages to try and work it out so thank you very much for solving it for me,

Kira

nortago
July 23rd, 2008, 03:39 PM
no problem yokiki :P