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();
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();