flash AS3.0无法访问空对象引用的属性或方法
文档类:package{importflash.display.Sprite;importflash.events.Event;publicclassFireWorkse...
文档类:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class FireWorks extends Sprite
{
var fires:Array;
var firesNumber:Number=1000;
var g:Number=0.1;
var i:uint;
var floor:Number=480;
var bounce:Number=-0.1;
public function FireWorks()
{
init();
}
private function init():void
{
fires=new Array();
for(i=0;i<firesNumber-1;i++)
{
var fire:Ball=new Ball(0xffffff*Math.random(),1);
fire.x=320;
fire.y=40;
fire.z=0;
fire.vx=Math.random()*9-6;
fire.vy=Math.random()*9-6;
fire.vz=Math.random()*9-6;
addChild(fire);
fires.push(fire);
}
addEventListener(Event.ENTER_FRAME,onEnterFrame01);
}
private function onEnterFrame01(e:Event):void
{
for(i=0;i<=firesNumber-1;i++)
{
var fire:Ball=fires[i];
moveFire(fire);
}
}
private function moveFire(fire:Ball):void
{
fire.vy+=g;
fire.x+=fire.vx;
fire.y+=fire.vy;
fire.z+=fire.vz;
if(fire.y>floor)//屏幕反弹
{
fire.y=floor;
fire.vy*=bounce;
}
}
}
}
2.Ball类
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var color:uint;
public var radius:uint;
public var mass:Number;
public var vx:Number=0;
public var vy:Number=0;
public var vz:Number=0;
public function Ball(color:uint=0x9acd32,radius:uint=40)
{
this.color=color;
this.radius=radius;
init();
}
private function init()
{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}
} 展开
package
{
import flash.display.Sprite;
import flash.events.Event;
public class FireWorks extends Sprite
{
var fires:Array;
var firesNumber:Number=1000;
var g:Number=0.1;
var i:uint;
var floor:Number=480;
var bounce:Number=-0.1;
public function FireWorks()
{
init();
}
private function init():void
{
fires=new Array();
for(i=0;i<firesNumber-1;i++)
{
var fire:Ball=new Ball(0xffffff*Math.random(),1);
fire.x=320;
fire.y=40;
fire.z=0;
fire.vx=Math.random()*9-6;
fire.vy=Math.random()*9-6;
fire.vz=Math.random()*9-6;
addChild(fire);
fires.push(fire);
}
addEventListener(Event.ENTER_FRAME,onEnterFrame01);
}
private function onEnterFrame01(e:Event):void
{
for(i=0;i<=firesNumber-1;i++)
{
var fire:Ball=fires[i];
moveFire(fire);
}
}
private function moveFire(fire:Ball):void
{
fire.vy+=g;
fire.x+=fire.vx;
fire.y+=fire.vy;
fire.z+=fire.vz;
if(fire.y>floor)//屏幕反弹
{
fire.y=floor;
fire.vy*=bounce;
}
}
}
}
2.Ball类
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var color:uint;
public var radius:uint;
public var mass:Number;
public var vx:Number=0;
public var vy:Number=0;
public var vz:Number=0;
public function Ball(color:uint=0x9acd32,radius:uint=40)
{
this.color=color;
this.radius=radius;
init();
}
private function init()
{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询