我还有一个问题一直困扰着我。这有点像我的另一个问题“使用 for 循环动画? ”的后续行动
这是我的代码: ball 是从名为 Ball 的外部类中提取的。
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.ui.Keyboard;
public class Dummy extends Sprite
{
private var balls:Array;
private var ball:Ball;
private var ballNum: Number = 10;
private var ax:Number = 4;
public function Dummy()
{
init();
}
private function init():void
{
balls = new Array();
for(var i:Number = 0; i < ballNum; i++)
{
ball = new Ball(Math.random() * 30);
ball.x = Math.random() * stage.stageWidth;
ball.y = Math.random() * stage.stageHeight;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
protected function onEnterFrame(event:Event):void
{
for(var i:int = 0; i < balls.length; i++)
{
balls[i].x += ax;
}
}
}
}