all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

Trying to create smooth movement


Trying to create smooth movement iappeal
2/1/2004 6:18:12 PM
flash actionscript:
I am working in Flash MX 2004 trying to create the look of a smooth movement. When clicking a button, the entire header movie rises to -100. If the header movie is already here, nothing is done. I included the code below. I am a beginner in Flash, so I'm sure there's a much easier way to handle this. I added a time delay to try to create a slow movement. Right now, when I step through the code it appears to work fine. When I test the movie, it waits for the time delay and then suddenly appears at -100. Please offer assistance. I would really appreciate any help anyone can offer!!

-Tom


===========================================================

function HeaderMovie() {

//capture y coordinate of Header movie
i = HeaderMov._y

//move movie up until y reaches -100
while (i > -100) {
i = i += -20;
setProperty("HeaderMov", _y, i)
TimeDelay()
}

HeaderMov.gotoAndPlay(17);

//move links movie
LinksMov._y = LinksMov._y = 150;
HomeButton.visible = true
}


function TimeDelay() {
//Time delay
var now = getTimer();
var wait = 1000;
while (now + wait > getTimer()) {
// do nothing
}
}

=========================================================

Re:Trying to create smooth movement kglad
2/1/2004 6:47:07 PM
use setInterval with a small enough time (50ms should work) and position increment to yield smooth motion.

Re:Trying to create smooth movement iappeal
2/1/2004 7:33:29 PM
Thank you for you help. The code I am using for setInterval() is not working. Please let me know if you see my errors. Thank you very much.

When clicking the link, I goToAndPlay(45). Frame 45 calls HeaderMovie(). The rest of the code is below:

function HeaderMovie() {

//while Header movie is not = -100, move up
while (HeaderMov._y > -100) {
setInterval(MoveMovie(), 50)
}
//end while

HeaderMov.gotoAndPlay(17);
LinksMov._y = LinksMov._y = 150;
Logo._y = Logo._y = 150;
HomeButton.visible = true;
LogoTop.visible = true;
}

function MoveMovie(){
setProperty("HeaderMov", _y, HeaderMov._y += -1);
}

-Tom

Re:Trying to create smooth movement kglad
2/1/2004 9:31:56 PM
try this:
function HeaderMovie() {
movemovieI = setInterval(MoveMovie, 50);
}
function MoveMovie() {
HeaderMov._y += -1;
if (HeaderMov._y<=-100) {
clearInterval(movemovieI);
HeaderMov.gotoAndPlay(17);
LinksMov._y = LinksMov._y=150;
Logo._y = Logo._y=150;
HomeButton.visible = true;
LogoTop.visible = true;
}
}

Re:Trying to create smooth movement iappeal
2/1/2004 9:45:35 PM
Thank you!!! Your code worked!

-Tom

Re:Trying to create smooth movement kglad
2/2/2004 5:40:11 AM
you're welcome.

Re:Trying to create smooth movement r2b2lynn
3/27/2004 9:12:24 PM
How can I change the setInterval() time?

For example, [b]initially[/b] I have it set to:
ID = setInterval(moveBox, 100);

But [b]later[/b] in the code, I would like it to change to:
ID = setInterval(moveBox, 50);

The speed should change.
How can I code that?


Here's some sample code, that doesn't work (change accordingly):
if (_root.cir1._y < 100) {
interval = 1;
}
if (_root.cir1._y > 100) {
interval = 10;
}
function dropCircle() {
_root.cir1._y += 1;
trace(_root.cir1._y);
updateAfterEvent();
}
setInterval(dropCircle,interval);

When the 2nd if condition is met, how come the variable interval is set to 1,
and not 10?
I can't figure this out.
Please help.


Re:Trying to create smooth movement kglad
3/28/2004 1:46:27 AM
you could just use

ID = setInterval(moveBox, 100);

early in your code and then later use:

clearInterval(ID);
setInterval(moveBox,50);

or if you wanted to be fancier and not rewrite the setInterval code you could
put in a function like:

function myIntervalCode(functionName,time,ID){
ID=setInterval(functionName,time);
}

you just have to remember to clear this interval at the appropriate time.
AddThis Social Bookmark Button