PDA

View Full Version : flash game help plz


shadowkeeper
06-18-2008, 05:32 AM
I have written the script but something is wrong in it. I wanted the object to be duplicated and randomly move towards the center of the stage. but the object is not at all being dupicated and the object is still.

Anyone please help with this....

var numItems = 10;
var stageX = Stage.width;
var stageY = Stage.height;
this.initAnimation = function() {
for (var i = 0; i<=numItems; i++) {
// Random Init position
var xpos = random(stageX);
var ypos = random(stageY);
// Attach movie & place in position
this.attachMovie("object_mc", "object_mc_"+i, i, {_x:xpos, _y:ypos});
var object = this["object_mc_"+i];
angle = 0;
agility = 10;
speed = random(10);
object .onEnterFrame = render();
}
};
// Calculate animation
this.render = function() {
var randomDirection = (Math.random()*2)-1;
var deviation = randomDirection*this.agility;
this.angle += deviation;
var rad = this.angle*(Math.PI/180);
var xpos = this.speed*Math.cos(rad);
var ypos = this.speed*Math.sin(rad);
trace("ypos"+ypos);
this._x = (this._x<=0) ? stageX : this._x+xpos;
this._y = (this._y<=0) ? stageY : this._y+ypos;
this._x %= stageX+1;
this._y %= stageY+1;
trace(this._x);
trace(this._y);
};
initAnimation();

rrh
06-18-2008, 06:24 AM
This may be the key:
object .onEnterFrame = render();

object .onEnterFrame = render;

The former assigns the return value of the function, the latter assign the function itself.

shadowkeeper
06-18-2008, 09:49 AM
thanks for the help but still it is not respawning i need them to respawn so that i can see all the bees at the same time

rrh
06-18-2008, 03:17 PM
There is also a difference between angle, agility, speed and object.angle, object.agility, and object.speed.