I’ve got two questions. Here is my code:
var speed:Number = 1.1;
trace(box.x);
button.addEventListener(MouseEvent.CLICK, moveBox);
function moveBox(evt:MouseEvent) {
button.addEventListener(Event.ENTER_FRAME, ease);
function ease(event:Event) {
[COLOR=Lime]var distance:Number = 400 - box.x;
var newDistance:Number = distance/speed;
box.x = 400 - newDistance;[/COLOR]
[COLOR=Red]//box.x = 400 – (400 – box.x) / speed;[/COLOR]
}
}
button.buttonMode = true;
Question 1: I’m trying to simplify the math. (Simplified math = [COLOR=Red]red[/COLOR], Math to simplify = [COLOR=SeaGreen]green[/COLOR]). However, when I have only the simplified code and comment out the longer math, I get this error:
[COLOR=Orange]1093: Syntax error.
1084: Syntax error: expecting rightparen before box.[/COLOR]
Can anyone explain to me why this is happening?
Question 2: Once I press my button to animate the box easing from left to right, I cannot reset the animation. e.g. I would like to press the button and start the animation over again every time I press the button, however, when I press the button again, nothing happens and the box fixes itself on the right after easing. Any help with this would be great.