styleBunny
Technical User
Hi Peeps,
I have created an enterframe script to tween a movie clip. The tween changes the _xscale/_yscale values (uniformly), and the _x and _y positions.
The script will increase the scale and move the x and y positions in one direction, but when i want it to decrease the scale back down again, or move x and y in the other direction, it wont work. Does it have something to do with the else if statement i have included to move the increment in the opposite direction?
Here is the code, its a bit of a dogs breakfast.
onClipEvent(enterFrame){
/*use an if statement to get an update sprite on each enterFrame, as a while or for statments never
refresh the stage until the condition is met.*/
if(z==1){
//create decrementing values passed from the unique values in each button.
trace(fridgeScale);
scaleSpeed= Math.abs((fridgeScale - _xscale)/5); //(scale / 5 iterations.)
trace("Current scaleSpeed interation value = " + scaleSpeed);
posSpeedX = Math.abs((newX - _x)/5); //(distance / 5 iterations.)
trace("Current posSpeedX interation value = " + posSpeedX);
posSpeedY = Math.abs((newY - _Y)/5); //(distance / 5 iterations.)
trace("Current posSpeedY interation value = " + posSpeedY);
//if statement to make sure the iterations of scaleSpeed, posSpeedX and posSpeedY dont get too small.
if(scaleSpeed <= 2){
scaleSpeed=2;
trace("ScaleSpeed got too small so i made it = " + scaleSpeed)
}
if(posSpeedX <= 2){
posSpeedX = 2;
trace("posSpeedX got too small so i made it = " + posSpeedX)
}
if(posSpeedY <= 2){
posSpeedY = 2;
trace("posSpeedY got too small so i made it = " + posSpeedY)
}
//adds the scaleSpeed increment to the movieClip, until it reaches desired scale(fridgeScale)
if (_xscale < fridgeScale) {
trace("Current Scale size = "+_xscale);
_xscale+=scaleSpeed;
_yscale+=scaleSpeed;
}else if (_xscale > fridgeScale) { //scales Down the size of the fridge mc.
trace("Current Scale size = "+_xscale);
_xscale-=scaleSpeed;
_yscale-scaleSpeed;
}
//subtracts the posSpeedX increment to the movieClip, until it reaches desired x pos(newX)
if(newX<_x){
_x-=posSpeedX;
}else if(newX>_x){ //move y postion of the movie clip in the opposite direction.
_x+=posSpeedX;
}
//subtracts the posSpeedY increment to the movieClip, until it reaches desired y pos(newY)
if(newY<_y){
_y-=posSpeedY;
}else if (newY>_y){//move y postion of the movie clip in the opposite direction
_y+=posSpeedY;
}
//enter this statment when the scale and x, y position has finished.
if(_xscale >= fridgeScale){
trace("Final Scale size = " + _xscale);
trace("Final x pos = " + _x);
trace("Final y pos = " + _y);
z = 0
}
}//end z = 1 statement.
}
Basically each time it enters the frame the increments(scaleSpeed, posSpeedX, posSpeedY) get smaller, to give an 'ease in' effect to the tween, and when the scale has been reached, it stops. Although to stop the increments getting too small i have implemented if statments that keep the iterations at a minimum value of 2.
What is it I need to move the scale in the opposite direction? if the new scale size(fridgeScale) is less than the current scale value, as well as move to new x,y locations (newX and newY) and if they are greater than the current positions? the else if part of my code dont seem to cut it!
The code that moves between the newX and _x positions may look incorrect, but this is because the x and y positions move into negitive numbers.
Cheers
Paul.
I have created an enterframe script to tween a movie clip. The tween changes the _xscale/_yscale values (uniformly), and the _x and _y positions.
The script will increase the scale and move the x and y positions in one direction, but when i want it to decrease the scale back down again, or move x and y in the other direction, it wont work. Does it have something to do with the else if statement i have included to move the increment in the opposite direction?
Here is the code, its a bit of a dogs breakfast.
onClipEvent(enterFrame){
/*use an if statement to get an update sprite on each enterFrame, as a while or for statments never
refresh the stage until the condition is met.*/
if(z==1){
//create decrementing values passed from the unique values in each button.
trace(fridgeScale);
scaleSpeed= Math.abs((fridgeScale - _xscale)/5); //(scale / 5 iterations.)
trace("Current scaleSpeed interation value = " + scaleSpeed);
posSpeedX = Math.abs((newX - _x)/5); //(distance / 5 iterations.)
trace("Current posSpeedX interation value = " + posSpeedX);
posSpeedY = Math.abs((newY - _Y)/5); //(distance / 5 iterations.)
trace("Current posSpeedY interation value = " + posSpeedY);
//if statement to make sure the iterations of scaleSpeed, posSpeedX and posSpeedY dont get too small.
if(scaleSpeed <= 2){
scaleSpeed=2;
trace("ScaleSpeed got too small so i made it = " + scaleSpeed)
}
if(posSpeedX <= 2){
posSpeedX = 2;
trace("posSpeedX got too small so i made it = " + posSpeedX)
}
if(posSpeedY <= 2){
posSpeedY = 2;
trace("posSpeedY got too small so i made it = " + posSpeedY)
}
//adds the scaleSpeed increment to the movieClip, until it reaches desired scale(fridgeScale)
if (_xscale < fridgeScale) {
trace("Current Scale size = "+_xscale);
_xscale+=scaleSpeed;
_yscale+=scaleSpeed;
}else if (_xscale > fridgeScale) { //scales Down the size of the fridge mc.
trace("Current Scale size = "+_xscale);
_xscale-=scaleSpeed;
_yscale-scaleSpeed;
}
//subtracts the posSpeedX increment to the movieClip, until it reaches desired x pos(newX)
if(newX<_x){
_x-=posSpeedX;
}else if(newX>_x){ //move y postion of the movie clip in the opposite direction.
_x+=posSpeedX;
}
//subtracts the posSpeedY increment to the movieClip, until it reaches desired y pos(newY)
if(newY<_y){
_y-=posSpeedY;
}else if (newY>_y){//move y postion of the movie clip in the opposite direction
_y+=posSpeedY;
}
//enter this statment when the scale and x, y position has finished.
if(_xscale >= fridgeScale){
trace("Final Scale size = " + _xscale);
trace("Final x pos = " + _x);
trace("Final y pos = " + _y);
z = 0
}
}//end z = 1 statement.
}
Basically each time it enters the frame the increments(scaleSpeed, posSpeedX, posSpeedY) get smaller, to give an 'ease in' effect to the tween, and when the scale has been reached, it stops. Although to stop the increments getting too small i have implemented if statments that keep the iterations at a minimum value of 2.
What is it I need to move the scale in the opposite direction? if the new scale size(fridgeScale) is less than the current scale value, as well as move to new x,y locations (newX and newY) and if they are greater than the current positions? the else if part of my code dont seem to cut it!
The code that moves between the newX and _x positions may look incorrect, but this is because the x and y positions move into negitive numbers.
Cheers
Paul.