hey all, I have a feeling this forum is going to become a second home
I have a loop in the flash file. it gives me a number of X & Y as the to & from coordinates and places a movieclip on the stage. I then have the tween class moving each clip as it is placed. the example is below:
for (var i:Number=1; i<=NumRows;i++){
ID = event.target.data["id_" + i] ;
xfrom = event.target.data["xfrom_" + i] ;
yfrom= event.target.data["yfrom_"+ i] ;
xto= event.target.data["xto_"+ i] ;
yto= event.target.data["yto_"+ i] ;
xcurrent= event.target.data["xcurrent_"+ i] ;
ycurrent= event.target.data["ycurrent_"+ i];
typeid= event.target.data["typeid_"+ i] ;
userid= event.target.data["user_"+ i] ;
var newShip = new BaseShip();
this.addChild(newShip);
SetupShip(newShip,xcurrent,ycurrent,xfrom,yfrom,xto,yto,10,ID);
I then have seperate functions … written below:
function SetupShip(ship:Object,currentx:Number, currenty:Number, xfrom:Number,yfrom:Number,xto:Number,yto:Number,engineSpeed:Number,ID:Number)
{
//get distance between current position and destination
var dist = Math.sqrt((ship.y - yto)*(ship.y - yto) + (ship.x - xto)*(ship.x -xto));
//set starting position
ship.x = currentx;
ship.y = currenty;
SetShipRotation (ship,xto,yto);
//begin ship en-route
MoveShip(currentx,currenty,xto,yto,ship,engineSpeed,dist,ID);
}
function SetShipRotation (ship:Object,xto:Number,yto:Number)
{
angle = Math.atan2(yto-ship.y, xto-ship.x);
angle *= radiansToDegrees;
angle = angle+90;
ship.rotation = angle;
}
function MoveShip(xfrom:Number,yfrom:Number,xto:Number,yto:Number,ship:Object,engineSpeed:Number,dist:Number,id:Number)
{
var ShipTween;
var SpeedDeduction = - engineSpeed;
var TimeToTravel = dist - engineSpeed;
//TimeToTravel = TimeToTravel * 3;
trace (TimeToTravel);
this["ShipTween"+id] = new Tween(ship,"y",None.easeNone,yfrom,yto,TimeToTravel,false);
this["ShipTween"+id] = new Tween(ship,"x",None.easeNone,xfrom,xto,TimeToTravel,false);
}
in the final MoveShip function I was hoping it would set each clip placed on the stage on its way. I have double checked at the xto yto xfrom yfrom variables are valid.
The problem is, the first animation loaded to stage does as it should. The second animation loaded begins on its path correctly but seems to abrubtly stop, a second after the first animation has reached its destination. If I keep re-trying the animation it does other wonderful things, its stops its horizontal descent and moves sideways off the stage :S… is there something I am doing wong.
I thought it may be something to do with the re-use of the ShipTween variable. But I have ‘hopefully’ changed it and made it more dynamic by appending the ID.
once again, any help would be awesome.
many thanks