PDA

View Full Version : slow move movieclip


caigriffith@gmail.com
05-22-2010, 04:40 AM
hi all,
this is my first time posting and i am quite a novice!

i have a simple arrangement where a movieclip moves to a new x y position when a button is clicked.
i want the movieclip to slowly move or 'glide' there instead of jumping straight to the new position.

heres the code..

btn_up.addEventListener(MouseEvent.CLICK, moveUp) ;

function moveUp(event:MouseEvent):void {

{
allcontent.x += 200;
allcontent.y += 200;

}

}

any help would be greatly appriciated!

thanks

snickelfritz
05-22-2010, 05:12 AM
Download the Greensock Tweening Platform. (http://blog.greensock.com/v11/) (TweenLite is the class you'll using for this)
Copy the included "com" folder to the same folder as your FLA.
This will allow Flash to find the tweening classes.

The following example tweens the movieclip using TweenLite and two variables.
Also includes an example of passing a value into a function that sets the framerate to 60fps during the animation, then sets it back to 12fps after the animation completes.
(this reduces CPU load while the movie is static)

import com.greensock.*;
import com.greensock.easing.*;

setFrameRate(12);

btn_up.addEventListener(MouseEvent.CLICK, moveUp);

function moveUp(e:MouseEvent):void
{
setFrameRate(60);
var _posX:Number = allContent.x + 200;
var _posY:Number = allContent.y + 200;

TweenLite.to(allContent, 1,
{
x:_posX,
y:_posY,
ease:Cubic.easeOut,
onComplete:setFrameRate,
onCompleteParams:[12]
});
}

function setFrameRate(_fr:Number):void
{
stage.frameRate = _fr;
}

caigriffith@gmail.com
05-22-2010, 12:01 PM
thanks for the quick reply im going to try this now!

caigriffith@gmail.com
05-22-2010, 12:14 PM
hey, the codes good i just get this error:

5007: An ActionScript file must have at least one externally visible definition.

caigriffith@gmail.com
05-22-2010, 12:23 PM
ahh i got it its becuase i think the code is in AS2..
is there any solution using AS3?

caigriffith@gmail.com
05-22-2010, 01:05 PM
my bad i downloaded the wrong greensock files..
thanks allot for your help!