732
Chapter 2: ActionScript Language Reference
Usage 3: This example uses a method of an object. You must use this syntax when you want to
call a method that is defined for an object.
obj = new Object();
obj.interval = function() {
trace("interval function called");
}
setInterval( obj, "interval", 1000 );
obj2 = new Object();
obj2.interval = function(s) {
trace(s);
}
setInterval( obj2, "interval", 1000, "interval function called" );
You must use the second form of the
setInterval()
syntax to call a method of an object, as shown
in the following example:
setInterval( obj2, "interval", 1000, "interval function called" );
When working with this function, you need to be careful about the memory you use in a SWF
file. For example, when you remove a movie clip from the SWF file, it will not remove any
setInterval()
function running within it. Always remove the
setInterval()
function by
using
clearInterval()
when you have finished using it, as shown in the following example:
// create an event listener object for our MovieClipLoader instance
var listenerObjectbject = new Object();
listenerObject.onLoadInit = function(target_mc:MovieClip) {
trace("start interval");
/* after the target movie clip loaded, create a callback which executes
about every 1000 ms (1 second) and calls the intervalFunc function. */
target_mc.myInterval = setInterval(intervalFunc, 1000, target_mc);
};
function intervalFunc(target_mc) {
// display a trivial message which displays the instance name and arbitrary
text.
trace(ta" has been loaded for "+getTimer()/1000+" seconds.");
/* when the target movie clip is clicked (and released) you clear the
interval and remove the movie clip. If you don't clear the interval before
deleting the movie clip, the function still calls itself every second even
though the movie clip instance is no longer present. */
target_mc.onRelease = function() {
trace("clear interval");
// clearInterval(this.myInterval);
// delete the target movie clip
removeMovieClip(this);
};
}
var jpeg_mcl:MovieClipLoader = new MovieClipLoader();
jpeg_mcl.addListener(listenerObject);
jpeg_mcl.loadClip("http://www.macromedia.com/software/central/images/
klynch_breezo.jpg", this.createEmptyMovieClip("jpeg_mc",
this.getNextHighestDepth()));
Summary of Contents for FLASH MX
Page 1: ...ActionScript Language Reference ...
Page 20: ...20 Contents ...
Page 24: ...24 Chapter 1 Introduction ...
Page 145: ...Button onKeyDown 145 See also Button onKeyUp ...
Page 202: ...202 Chapter 2 ActionScript Language Reference See also break default strict equality switch ...
Page 282: ...282 Chapter 2 ActionScript Language Reference See also break continue while ...
Page 383: ...LoadVars addRequestHeader 383 See also XML addRequestHeader ...
Page 388: ...388 Chapter 2 my_lv load place a valid URL pointing to a text file here ...
Page 463: ...Microphone setRate 463 See also Microphone rate ...
Page 469: ...Microphone silenceLevel 469 See also Microphone gain Microphone setSilenceLevel ...
Page 480: ...480 Chapter 2 ActionScript Language Reference See also Mouse addListener ...
Page 529: ...MovieClip globalToLocal 529 See also MovieClip getBounds MovieClip localToGlobal ...
Page 612: ...612 Chapter 2 ActionScript Language Reference See also MovieClipLoader onLoadStart ...
Page 623: ...NetConnection class 623 See also NetStream class Video attachVideo ...
Page 649: ...Number 649 See also NaN Number class ...
Page 679: ...on 679 on release trace X this _x trace Y this _y stopDrag See also onClipEvent ...
Page 683: ...onUpdate 683 buttonLabel textColor my_mc labelColor ...
Page 788: ...788 Chapter 2 ActionScript Language Reference See also private public ...
Page 1001: ...Video height 1001 my_mc _height my_mc my_video height See also MovieClip _height Video width ...
Page 1022: ...1022 Chapter 2 ActionScript Language Reference See also XML createElement ...
Page 1057: ...XML xmlDecl 1057 See also XML docTypeDecl XML toString ...
Page 1070: ...1070 Chapter 2 ActionScript Language Reference ...
Page 1104: ...1104 Appendix Deprecated Language Elements ...