以下代码试图分配(当场制作的bloodyParticle属性)forceX和forceY,随机数。 但问题是所有三个实例的随机数都相同。
for(var k:int = 0; k<3; k++)
{
var bloodyParticle:BloodyParticle = new BloodyParticle();
bloodyParticle.forceX = Math.random() * 20 - 10;
bloodyParticle.forceY = Math.random() * -20 + 10;
bloodyParticle.addEventListener(Event.ENTER_FRAME, bloodyParticleLoop);
bloodyParticle.x = bloodyPoint.x;
bloodyParticle.y = bloodyPoint.y;
}
好的,根据评论,这是我如何使用它们
private function bloodyParticleLoop(e:Event)
{
bloodyBmd.fillRect(bloodyBmd.rect, 0);
bloodyBmd.draw(MovieClip(e.target),MovieClip(e.target).transform.matrix);
//tried e.target also
e.target.x += e.target.forceX;
e.target.y += e.target.forceY;
e.target.forceY++;
}
并且forceX和forceY的getter / setter之前不存在,但我刚刚在类中看到它现在看起来像这样
包 {
import flash.display.MovieClip;
public class BloodyParticle extends MovieClip
{
public var forceX:Number;
public var forceY:Number;
public function BloodyParticle()
{
forceX = Math.random() * 20 - 5; //cz i hav the random number here-
forceY = Math.random() * -20 + 10;//-i commented the earlier
//-initialization of forceX/Y
}
}
}