View comments | RSS feed

onData (MovieClip.onData handler)

onData = function() {}

Invoked when a movie clip receives data from a MovieClip.loadVariables() call or a MovieClip.loadMovie() call. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class and is linked to a symbol in the library.

You can use this handler only with the MovieClip.loadVariables() method or the loadVariables() global function. If you want an event handler to be invoked with MovieClip.loadMovie() method or the loadMovie() function, you must use onClipEvent(data) instead of this handler.

Availability: ActionScript 1.0; Flash Player 6

Example

The following example illustrates the correct use of MovieClip.onData(). It loads a file named OnData.txt from the same directory as the FLA. When the data from the file is loaded into the MovieClip object, onData() executes and we trace out the data.

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());

mc.onData = function() {
    for(var i in this) {
        trace(">> " + i + ": " + this[i]);
    }
}

mc.loadVariables("OnData.txt");

See also

onClipEvent handler, loadVariables (MovieClip.loadVariables method)


Version 8

Comments


Fumio Nonaka said on Oct 17, 2005 at 6:57 AM :
This handler can be used with MovieClip.loadVariables() method or
loadVariable() function. It will not be invoked when
MovieClip.loadMovie() method or loadMovie() function is called to the
MovieClip even if the handler is defined in a class that is associated with
its symbol.

[Wrong]:
Invoked when a movie clip receives data from a
MovieClip.loadVariables() call or a MovieClip.loadMovie() call.

[Correct]:
Invoked when a movie clip receives data from a
MovieClip.loadVariables() call.
Fumio Nonaka said on Oct 17, 2005 at 7:47 AM :
Declaring a variable of the same name as a MovieClip instance is not a
good practice. Two identifiers exist in the same timeline.

// [Debug] > [List Variables]
Variable _level0.mc = [movieclip:_level0.mc]
Movie Clip: Target="_level0.mc"

I recommend to change the statement like the following:
var mc:MovieClip = this.createEmptyMovieClip("my_mc",
this.getNextHighestDepth());

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002487.html