ok,
so lets assume you have a movieclip called "SomeMovieClip"
that is 20 frames total. and you want it to play frame 1-10
before the click, and 11 = 20 after the click, and you want the
click event to toggle the boolean, this code *should* work...
(i wrote this in the comment box, so i haven't tested it)
var clicked:Boolean = false;
var mc:MovieClip = new SomeMovieClip();
mc.x = mc.y = 100;
mc.addEventListener(MouseEvent.CLICK, onClick);
addChild(mc);
this.addEventListener(Event.ENTER_FRAME, loop);
private function onClick(e:MouseEvent):void {
if (clicked) {
clicked = false;
} else {
clicked = true;
}
private function loop(e:Event):void {
if(!clicked) {
if(mc.currentFrame > 10) {
mc.nextFrame();
} else {
mc.gotoAndStop(1);
}
} else {
if(mc.currentFrame < 21) {
mc.nextFrame();
} else {
mc.gotoAndStop(11);
}
}
}
thinking about the code i just posted,
yew can actually to the same thing faster
and more efficiently with this code...
var clicked:Boolean = false;
var mc:MovieClip = new SomeMovieClip();
mc.x = mc.y = 100;
mc.play();
mc.addEventListener(MouseEvent.CLICK, onClick);
addChild(mc);
addEventListener(Event.ENTER_FRAME, loop);
private function onClick(e:MouseEvent):void {
//--inline conditionals FTW!
clicked = (clicked) ? (false) : (true);
}
private function loop(e:Event):void {
if(!clicked) {
if(mc.currentFrame == 10) {
mc.gotoAndPlay(1);
}
} else {
if(mc.currentFrame == 20) {
mc.gotoAndPlay(11);
}
}
}
so what's the difference?
well the onClick function now uses an inline conditional
verses the classic if/else statement (a bit faster + less code).
also im letting flash handle the animation as opposed to
letting our code to the logic. in the first example in the
enterframe loop, im checking the movieclips current frame
then incrementing or resetting it. while in the second
example im just checking the current frame. when the
check condition fails THEN i take action, as opposed to
taking action on every frame loop. will that make a huge
difference? not in this example. but if you were doing this
many many times per frame it would start to...
i hope that helps!