When my variable reaches the number 94, i am not redirected to the frame “two”. Any suggestions?
import flash.events.Event;
stop();
//addEventListener(Event.ENTER_FRAME,cakeShow);
var cakeSize:Number = 100;
cakeButton.addEventListener(MouseEvent.CLICK,decCake);
function decCake(event:MouseEvent):void {
cakeSize--;
cake.text = String (cakeSize);
}
cake.text = String(cakeSize);
if (cakeSize==94) {
gotoAndStop("two");
}
You only check your variable once, you should do it every time something happens. So, you have to update your function.
Update: Seeing you need to constantly monitor a variable, you need to declare it as a property.
This way a “set” function (aka “setter”) is called every time you need to set a value to a variable, and “get” function (aka “getter”) is called every time you check its value. So you let that
cakeSize--;remain in place, but in reality Flash will first call getter, take its returned value, decrement it and call setter with the new value. Note, you will have to provide special behavior for the setter function should you need to go to frame “two” once or under certain conditions and not every time cakeSize is assigned the value 94.