init(s)
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
ball = new animation_ch15_Ball(15);
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
frame(s)
private function onEnterFrame(event:Event):void
{
xpos += vx;
ypos += vy;
zpos += vz;
var radius:Number = ball.radius;
if(xpos + radius > right)
{
xpos = right - radius;
vx *= -1;
}
else if(xpos - radius < left)
{
xpos = left + radius;
vx *= -1;
}
if(ypos + radius > bottom)
{
ypos = bottom - radius;
vy *= -1;
}
else if(ypos - radius < top)
{
ypos = top + radius;
vy *= -1;
}
if(zpos + radius > front)
{
zpos = front - radius;
vz *= -1;
}
else if(zpos - radius < back)
{
zpos = back + radius;
vz *= -1;
}
case(s)
if(zpos > -fl)
{
var scale:Number = fl / (fl + zpos);
ball.scaleX = ball.scaleY = scale;
ball.x = vpX + xpos * scale;
ball.y = vpY + ypos * scale;
ball.visible = true;
}
else
{
ball.visible = false;
}
}
}
}