First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Bart Portier | Website:

New MX functions: part 2

setInterval, clearInterval, clear method

Hi everyone,

I hope you liked the first part of this tutorial. Remember? The one where we used the Drawing Object to create a triangle with script.

It's fun being able to draw something, but now we want to know what we can do with our drawing:

- how can I talk to the instances that we just create them? (what 's the path I can use)
- how can I change the appearance of what I was drawing? (can I use setProperty?)
- how can I time my drawing the way I would in a Movie Tween? (i.e. pausing the drawing for a while)

PS... I would make a small tribute to all designers and develloppers who made timer functions, they already wrote ways to use dynamic drawing and timer-functions, which were very inventive. We are the guys who are spoilt now, because Macromedia made specific functions for us. Thanks Macromedia, and thanks to the other guys who made things Macromedia wouldn't even have considered :-)

part A: setInterval and clearInterval.

Movie Setup:

I'm not drawing triangles in these examples. I'm just drawing a line, to keep things as straightforward as possible for everyone.

This is the effect I want to achieve:

and this is the script I used

The script

In frame 1 of the first timeline I put this function:

function drawMe() {
_root.createEmptyMovieClip( "triangle"+i , i);
with ( _root["triangle"+i]);
lineStyle( 5, 0xff00ff, 100 );
moveTo(i, 10 );
lineTo( i,300 );
//lineTo( 100, 300 );
//lineTo( 200, 200 );
i = i + 10;
trace ("has been called" + i);
j = i/10;

this function creates a MovieClip, defines the line, and draws it (very much the same as in our first tutorial). I commented out what we used in the first tutorial. I also added some trace information to show you what is happening.

This is the code behind the start button:

on (release) {
var quitID;
quitID=setInterval(drawMe, 1000);
trace (quitID);

the most important line here is the setInterval. It starts the drawMe function and executes it every 1000 miliseconds. You could leave out the variable quitID if you wanted and just write it like this:

on (release) {
setInterval(drawMe, 1000);
trace (quitID);

it would work just as well, only I want to stop it too. That's why I need some feedback from the function (ie. quitID, so I can stop it using the clearInterval method. Indicating the quitID he knows what functions should be stopped.

This is the code behind the start button:

on (release) {
clearInterval( quitID );

Now I can stop and start things and simulated motion, I want to erase what I have been drawing.

» Level Intermediate

Added: 2002-04-09
Rating: 6 Votes: 11
(10 being the highest)
» Author
MCT and Macromedia Trainer and designer
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.