Shaking text
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Shaking text

  1. #1
    Who, What, Why ... ? Fraggs's Avatar
    Join Date
    Jul 2003
    Location
    Flashland .. where else ?
    Posts
    786

    Shaking text

    Is there an actionscript code that can make text shake and if not, is it possible to make the text shake?

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    there would be several ways to shake text, for example this creates the text and makes it shake using only actionscript

    code:

    // set up some variables to control how the text shakes
    var pos = {x: 100, y: 50}; // the position of the text
    var lim = 20; // how far should the text be able to shake
    var msg = "shake it baby"; // the text to display
    var spd = 50; // how fast should the text shake (here 50 is 50 milliseconds)

    var shake = this.createEmptyMovieClip("shakingText", 1);
    shake.createTextField("shakeText", 1, 0, 0, 100, 20);
    shake.shakeText.autoSize = "left";
    shake.shakeText.text = msg;

    function doShake(mc) {
    var x, y;
    do {
    // set the x position around the original position of the text
    x = pos.x + (Math.random() - 0.5 * lim);
    } while (x < pos.x - lim || x > pos.x + lim);
    do {
    // set the y position around the original position of the text
    y = pos.y + (Math.random() - 0.5 * lim);
    } while (y < pos.y - lim || y > pos.y + lim);
    mc._x = x;
    mc._y = y;
    }
    // keep calling the doShake function every spd milliseconds
    // the function is passed a reference to the shake movie clip
    var intID = setInterval(doShake, spd, shake);



    to stop the text shaking you can clear the interval using,

    clearInterval(intID);

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

Poll by Flashkit.com