To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 09-30-2004, 03:07 PM   #1
fallacy
Member
 
Join Date: Jan 2003
Posts: 78
Elastic question Please help:)

I have a real simple question:
I want to make text slide in horizontally, come to it’s location, but it goes past it a little bit bouncing back and forth a few times before it stops.

I would like to do this effect with a motion tween but I don’t want to key frame the effect, I want to do it with action script. Can this be done? I looked up and down this entire forum and could not find an example of this.

If anybody can do this can you Please, Please, Please post the .fla

Thanks
__________________
chris davis
fallacy is offline   Reply With Quote
Old 09-30-2004, 03:31 PM   #2
k/smaert
Senior Member
 
k/smaert's Avatar
 
Join Date: Dec 2003
Posts: 210
personally i use an extension for doing things like this. check out http://proto.layer51.com/d.aspx?f=1142 for more info.

this .mxp makes wonders for me.
k/smaert is offline   Reply With Quote
Old 09-30-2004, 03:41 PM   #3
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
I like to write these kinds of things myself.
Here's a quicky version. Just attach this script to the first frame of a new movie. Set it to 30 fps for smoother motion.

Taking the time to figure out exactly how this script works will make you a better person


code:

MovieClip.prototype.springyXTween = function(destX,stiffK,dampK)
{
this.destX = destX;
this.stiffK = stiffK;
this.dampK = dampK;
this.vx = 0; // this represents the velocity

this.onEnterFrame = function()
{
// by storing the motion in the velocity variable, we retain inertia
// and get the springy effect you want
this.vx += (this.destX - this._x)*this.stiffK;
// this line causes the motion to lose energy over time, otherwise we'd keep bouncing
this.vx *= this.dampK;
this._x += this.vx;
// this checks to see if we're there yet, if so we stop calling this function
if (Math.abs(this.vx) < .1 && Math.abs(this.destX - this._x) < .1)
{
this._x = this.destX;
delete this.onEnterFrame;
}
}
}

// Create offscreen movie with a text field.
// If you have an existing movie to tween, use that.
_root.createEmptyMovieClip('txt_mc', 1);
txt_mc._x = -100;
txt_mc.createTextField('my_txt', 1, 10, 10, 100, 50);
txt_mc.my_txt.setNewTextFormat(new TextFormat('Courier New', 24, 0x000077, true));
txt_mc.my_txt.text = "sproing!";

// Below is where we set up our tween.
// The first number is the desired destination
//
// Play with the second two numbers (0.1) and (0.7) to
// get different kinds of springy motion.
//
// The second number (0.1) represents the spring stiffness
// (how fast the spring snaps to position) - higher values
// will make the spring travel faster, but may also make it
// go out of control if too high. Don't use values much higher than .5.
//
// and the third number (range 0.1 to 0.999) represents damping or
// viscosity - lower values will make the object act like it is in heavy oil

txt_mc.springyXTween(300, 0.1, 0.7);




For more examples of things moving with springy motion, see my website (link below).
__________________

Last edited by jbum; 09-30-2004 at 03:49 PM.
jbum is offline   Reply With Quote
Old 09-30-2004, 05:45 PM   #4
fallacy
Member
 
Join Date: Jan 2003
Posts: 78
...

thanks for replys, but there is nothing on your site that i was looking for k/smaert.

Jbum looks like you have code that creats a text field onload but i am looking to do it with already created text with a motion tween on it.

I am begeining to think there is no way to to it "cries".
__________________
chris davis
fallacy is offline   Reply With Quote
Old 09-30-2004, 05:49 PM   #5
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
If you want to use an existing movie clip, then simply remove these lines:

code:

_root.createEmptyMovieClip('txt_mc', 1);
txt_mc._x = -100;
txt_mc.createTextField('my_txt', 1, 10, 10, 100, 50);
txt_mc.my_txt.setNewTextFormat(new TextFormat('Courier New', 24, 0x000077, true));
txt_mc.my_txt.text = "sproing!";



and substitute the name of your pre-existing movieclip for txt_mc, in the last line of the script.

If your text field is not currently inside a symbol movieclip, then put it inside one by using convert-to-symbol. This makes it easier to manipulate via actionscript. Use the properties panel to assign the name 'txt_mc' (or whatever you want to use) to the new symbol.

- Jim
__________________
jbum is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:44 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.