Groups | Blog | Home
all groups > flash actionscript > november 2005 >

flash actionscript : easing to _X position



jonako13
11/18/2005 9:51:51 PM
I'm sure there are better ways to script it than I was trying, but my idea was
kind of like being in the middle of a room with 4 walls.The stage would be like
a static camera facing one wall. The room starts to revolve slowly picking up
speed. The room continues to spin at it's max speed for a couple seconds and
then gradually slows down and stops on a different wall in front of the static
camera.
I wanted to be able to have four buttons that would activate this spinning and
each tell it to stop at a different wall.
I thought the easiest way would be to have a movie clip with the four walls in
it.
Everything seems to work except the easing out to an _x position. The X pos is
set onRelese button.

If you can think of a better way to code this or a fix to my code I greatly
appreciate it. If you want the .fla please let me know. Any help is appreciated
since I am stuck.

Thanks,

jonathan:confused;

velocity=1;
maxVelocity=50;
bgendx=0;

function doBGstart () {
_root.createEmptyMovieClip('velo', 5000);
velo.onLoad = function(){
motioncount=1;
}
velo.onEnterFrame = function() {
motioncount++;
trace("motioncounter=" + motioncount);
trace("velocity="+_root.velocity);
trace("Background1 x pos="+_root.bg.bg1._x);
_root.bg.bg2._x-=_root.velocity;
_root.bg.bg1._x-=_root.velocity;
if (_root.bg.bg1._x<= -706) {
_root.bg.bg1._x = _root.bg.bg2._x + 690;
}
if (_root.bg.bg2._x<= -706) {
_root.bg.bg2._x = _root.bg.bg1._x + 690;
}
if (_root.velocity<50) {
_root.velocity=_root.velocity*1.21;
}
if(_root.velocity>=50){
_root.velocity = _root.velocity;

}


if(motioncount>=150){
_root.doBGend();
trace("nextfunction");
delete this.onEnterFrame;
}
}
}
function doBGend () {
_root.createEmptyMovieClip('velo3', 5001);
var totalFrames = 300; // How many frames our tween will take.
var currentFrame = 1; // How many frames have passed so far.
var startX = _root.stage._width; // The starting position
of our object.
var endX = _root.bgendx; // The ending position of our
object.
var changeInX = endX - startX; // The distance our object will travel
(450 pixels).

velo3.onEnterFrame = function() {
_root.bg.bg2._x-=_root.velocity;
_root.bg.bg1._x-=_root.velocity;
if (_root.bg.bg1._x<= -706) {
_root.bg.bg1._x = _root.bg.bg2._x + 690;
}
if (_root.bg.bg2._x<= -706) {
_root.bg.bg2._x = _root.bg.bg1._x + 690;
}
if (_root.velocity>1) {
_root.velocity=_root.velocity*0.7;
if(_root.velocity<=1){
_root.doFinal();
}
}
trace("Background1 x pos="+_root.bg.bg1._x);
trace("velocity="+velocity);

}
}


//
function doFinal(){
_root.createEmptyMovieClip('velo4', 5002);
//____________________________________________
//
var start = _root.stage._width;
var end = _root.bgendx;
var percent = 0;
var percentIncrease = .05;
velo4.onEnterFrame = function() {
if(_root.bg.bg1._x==(_root.stage._width)){
_root.bg.bg1._x = start + (end - start)*Ease.outUsing(Ease.exponential,
percent);
percent += percentIncrease;

if (percent >= 1){
percent = 0;
}
}
}
}
redl3tt3r
11/18/2005 10:54:43 PM
Hey John,

[quoted text, click to view]
and easeing function. It may help you out.

-redLetter

function easePosition(theClip, targetX, targetY, speed){
// The Ease_x Function
if (targetX > theClip._x) {
theClip._x += (targetX-theClip._x)/speed;
//Force to final position
if (theClip._x > (targetX-0.5)) {
theClip._x = targetX;
};
} else if (targetX < theClip._x) {
theClip._x += (targetX-theClip._x)/speed;
//Force to final position
if (theClip._x < (targetX+0.5)) {
theClip._x = targetX;
};
}; // END Ease_x Function

// The Ease_y Function
if (targetY > theClip._y) {
theClip._y += (targetY-theClip._y)/speed;
//Force to final position
if (theClip._y > (targetY-0.5)) {
theClip._y = targetY;
};
} else if (targetY < theClip._y) {
theClip._y += (targetY-theClip._y)/speed;
//Force to final position
if (theClip._y < (targetY+0.5)) {
theClip._y = targetY;
};
}; // END Ease_y Function
}; //END easePosition


To use it all you have to do it call the function like this:
--------------------------------
easePosition(theClip, targetX, targetY, speed);

filled in it looks like this:
--------------------------------
easePosition(movieclip, 250, 300, 5);

Note
--------------------------------
The larger the number you put for the speed the slower it moves.
sampurtill
11/18/2005 11:38:56 PM
var ease:Function = mx.transitions.easing.Regular.easeOut;
private function easeY(target_mc:MovieClip, easeType, endY:Number,
tweenTime:Number) {
var myApp:Object = this;
var roTween:Tween = new Tween(target_mc, "_y", easeType, target_mc._y, endY,
tweenTime, false);
roTween.onMotionFinished = function() {
};
}

This will ease in the _y, and once it finishes you can call any function you
want inside onMotionFinished.

You need to use this code to make it work:

easeY(target_mc, ease, 200, 30)

The tween time is in frames, it just is more smooth.

Sam
AddThis Social Bookmark Button