Is there an actionscript code that can make text shake and if not, is it possible to make the text shake?
Printable View
Is there an actionscript code that can make text shake and if not, is it possible to make the text shake?
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);