A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Elastic question Please help:)

  1. #1
    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 its 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 dont 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

  2. #2
    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.

  3. #3
    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 02:49 PM.

  4. #4
    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

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center