Flash Script – Cursor-Responsive Text

By Georgina Laidlaw

1. Create a text field, name it "txt", and then convert it to a movieclip.

2. Give the movie clip an instance name of "a1".


3. Create a new movieclip and give it an instance name of "a0".

4. Create layers as shown below.


5. In the actions layer in the first key frame, insert the following action:

x = new Array();  
y = new Array();  
text = "Flashcircle.com";  

// mx x value of movieclip  
mx = getProperty("/a1", _x);  
txtlength = length(text);  
/a1:txt = "F";  

//loop through to create duplicate movieclip  
for (i=2; i<=txtlength; i++)  
duplicateMovieClip ("/a1", "a" add i, i);  
setProperty ("/a" add Number(i), _x, mx);  

// substring to put individual letter into movieclip  
set ("/a" add Number(i) add ":txt", substring(text, i, 1));  

6. In the actions layer in the third key frame, insert these actions:

//code to make the text follow  
for(i=1; i<=txtlength; i++)  
x[i] = getProperty("/a" add Number(i-1),_x);  
y[i] = getProperty("/a" add Number(i-1),_y);  
x[i] = x[i]+10;  

7. In the actions layer in the fourth key frame, insert the following:

//code to make the text follow  
for (i=1; i<=txtlength; i++)  
setProperty ("/a" add i, _x, x[i]);  
setProperty ("/a" add i, _y, y[i]);  
gotoAndPlay (2);

8. Right click the "a0" instance movie clip, and insert these actions:

onClipEvent (load)  
startDrag ("", true);  

9. Easy, wasn’t it? Press ctrl+enter to test you movie.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.