What's wrong with this animation code?
Being the 'pro' I am I always think I have the solution, only to keep running into problems. The following AS3 code is supposed to shrink a ball to no less than 15 px, and once it reaches 15px, it's supposed to grow to no bigger than its original size, and then shrink again, grow again, etc.
Actionscript Code:
var originalsize:Number=ball_mc.size; [I]//original size of ball to be animated[/I]
ball_mc.addEventListener(Event.ENTER_FRAME, grow_shrink);
function grow_shrink() { [I]//holds both shrink and grow functions[/I]
function start_shrink() {
ball_mc.size-=5; //shrink by 5 per onEnterFrame
if(ball_mc.size<=15) {
ball_mc.size=15 [I]//not to shrink below 15px[/I]
start_grow(); [I]// if ball reaches 15 in size, call start_grow()[/I]
}
}
}
function start_grow() {
ball_mc.size+=5; [I]//grow by 5 per onEnterFrame[/I]
if(ball_mc.size>=originalsize) {
ball_mc.size=originalsize [I]//not to exceed original size[/I]
start_shrink() [I]//call shrink function above[/I]
}
}
}
First of all, the ball shrinks to only 20px not 15 as it's supposedly programmed to. And after that it never grows back to original size as intended, but keeps getting resided randomly between 18 and 22px, as I'm tracing it. Where is the logic here wrong?
I've tried other variations, all have failed with the objective. Plus I'm getting this output
"18.6
ArgumentError: Error #1063: Argument count mismatch on HT_fla::text_2/grow_shrink(). Expected 0, got 1."
Also, the[i] I've no idea why they're showing, the italic was meant to separate comments better, but created more mess instead:).