这是AS文件:
package{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class Removal extends Sprite{
private var balls:Array;
private var count:int=20;
public function Removal(){
init();
}
private function init():void{
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
balls=new Array();
for(var i:Number=0;i<count;i++){
var ball:Ball=new Ball(10);
ball.x=Math.random()*stage.stageWidth;
ball.y=Math.random()*stage.stageHeight;
//ball.vx=Math.random()*5;
//ball.vy=Math.random()*5;
ball.vx=Math.random() * 2 - 1;
ball.vy=Math.random() * 2 - 1;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(event:Event):void{
for(var j:Number=balls.length;j>0;j--){
var ball:Ball=new Ball(balls[j]);
ball.x+=ball.vx;
ball.y+=ball.vy;
if(ball.x-ball.radius>stage.stageWidth||
ball.x+ball.radius<0||
ball.y-ball.radius>stage.stageHeight||
ball.y+ball.radius<0)
{
removeChild(ball);
balls.splice(j,1);
if(balls.length<=0){
removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
}
}
}
}
运行后,在“输出”里出现了这样:
ArgumentError: Error #2004: 某个参数无效。
at flash.display::Graphics/drawRoundRect()
at flash.display::Graphics/drawCircle()
at Ball/init()
at Ball$iinit()
at Removal/::onEnterFrame()
jc:fighting 求高手帮忙~~~
还有附上Ball.as文件的内容:
package{
import flash.display.Sprite;
public class Ball extends Sprite{
public var radius:Number;
private var color:uint;
public var vx:Number=0;
public var vy:Number=0;
public function Ball(radius:Number=40,color:uint=0xff0000)
{
this.radius=radius;
this.color=color;
init();
}
public function init():void{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}
} |