Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a movie clip to smoothly move in one direction and decelerate 1

Status
Not open for further replies.

krigbert

Programmer
Jun 2, 2005
95
NO
It's kind of hard to be descriptive here, but I want one movie clip to move downwards on a page, quickly at first, then decelerating. So I write this in the first frame of the movie clip:

while(this._y<500){
mango=(500-this._y)/30;
this._y += mango;
}

Now, when I do this, I get the old message about my scripting slowing my computer down.

Why isn't it working properly? :l
 
> Now, when I do this, I get the old message about my scripting slowing my computer down.
>
> Why isn't it working properly? :l

Because in your script "this._y" never gets to 500, your computer goes to infinite loop. Flash is designed to give you the message after repeating same thing 256 times.

1. Delete your script from the MovieClip.
2. Name your MovieClip on Stage as "mc".
3. Put this script in the frame 1 of the main timeline.

[tt]//
this.onEnterFrame = function() {
mc._y += (500-mc._y)/30;
};
stop();
//[/tt]

Kenneth Kawamoto
 
Well, that doesn't do anything at all :l

You're probably right about the problem, though. Could it be solved with math.round somehow, maybe?
 
I can assure you it works. (I've even tested it.) Perhaps you didn't follow what I said - did you name your MovieClip? Did you put the script in the main timeline?

> Could it be solved with math.round somehow, maybe?

No - problem of your script is that even if you solved the infinite loop issue, it will execute in milliseconds and you won't see any animation!

Kenneth Kawamoto
 
I did not put it in frame one of my main timeline, but in frame 2. I also didn't rename my MC, but kept it at the current name (teppenede) and changed the code you gave me to reflect that (i.e. "teppenede._y += (500-teppenede._y)/30;") - I don't see how that would make a difference, tho.

Also, I don't see why you have to have the stop(); there.
 
If you don't have "stop()" the playhead moves to the next frame.

The MovieClip name is not the name given in the Library, it's the name given to the instance on Stage - just in case.

Add this trace. What do you get?

[tt]// main timeline
trace("teppenede: "+teppenede);
this.onEnterFrame = function() {
teppenede._y += (500-teppenede._y)/30;
};
stop();
//[/tt]

Kenneth Kawamoto
 
Haha, it just had to be something stupid like that, didn't it? :p

You're right - I used the name in the library in stead of the instance name.
 
Uh, oh, new problem: It's supposed to accelerate rather than decelerate. How do I reverse it? I'm wringing my brain here, but I'm not all that amazing when it comes to math :(

illustration and webdesign
 
You can do something like:

[tt]// main timeline
this.onEnterFrame = function() {
if (teppenede._y<1) {
teppenede._y = 1;
} else if (teppenede._y>500) {
teppenede._y = 500;
delete this.onEnterFrame;
} else {
teppenede._y *= 2;
}
};
stop();
//[/tt]

Another way (better way) is to use Flash's bundled Tween class:

[tt]// main timeline
import mx.transitions.Tween;
import mx.transitions.easing.*;
new Tween(teppenede, "_y", Strong.easeIn, 0, 500, 3, true);
stop();
//[/tt]

If you're interested have a look at this article:
<
Kenneth Kawamoto
 
I did this:

//
this.onEnterFrame = function() {
mc._y += (1/mc._y)*300;
};
stop();
//

I didn't know the easing could be set to above 100 using actionscript, though. But I think the above'll do.

illustration and webdesign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top