03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Usage 2: The following example defines two event h<strong>and</strong>lers <strong>and</strong> calls each of them. The first<br />

call to setInterval() calls the callback1() function, which contains a trace() statement.<br />

The second call to setInterval() passes the "interval called" string to the function<br />

callback2() as a parameter.<br />

function callback1() {<br />

trace("interval called");<br />

}<br />

function callback2(arg) {<br />

trace(arg);<br />

}<br />

setInterval( callback1, 1000 );<br />

setInterval( callback2, 1000, "interval called" );<br />

Usage 3: This example uses a method of an object. You must use this syntax when you want<br />

to call a method that is defined for an object.<br />

obj = new Object();<br />

obj.interval = function() {<br />

trace("interval function called");<br />

}<br />

setInterval( obj, "interval", 1000 );<br />

obj2 = new Object();<br />

obj2.interval = function(s) {<br />

trace(s);<br />

}<br />

setInterval( obj2, "interval", 1000, "interval function called" );<br />

You must use the second form of the setInterval() syntax to call a method of an object, as<br />

shown in the following example:<br />

setInterval( obj2, "interval", 1000, "interval function called" );<br />

When working with this function, you need to be careful about the memory you use in a<br />

SWF file. For example, when you remove a movie clip from the SWF file, it will not remove<br />

any setInterval() function running within it. Always remove the setInterval() function<br />

by using clearInterval() when you have finished using it, as shown in the following<br />

example:<br />

// create an event listener object for our MovieClipLoader instance<br />

var listenerObjectbject = new Object();<br />

listenerObject.onLoadInit = function(target_mc:MovieClip) {<br />

trace("start interval");<br />

/* after the target movie clip loaded, create a callback which executes<br />

about every 1000 ms (1 second) <strong>and</strong> calls the intervalFunc function. */<br />

target_mc.myInterval = setInterval(intervalFunc, 1000, target_mc);<br />

};<br />

Global Functions 75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!