View comments | RSS feed

MovieClip.onData

Availability

Flash Player 6.

Usage

my_mc.onData = function() {
   // your statements here
}

Parameters

None.

Returns

Nothing.

Description

Event handler; invoked when a movie clip receives data from a MovieClip.loadVariables() or 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 or is linked to a symbol in the library. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.

This handler can be used only with movie clips for which you have a symbol in the library that is associated with a class. If you want an event handler to be invoked when a specific movie clip receives data, you must use onClipEvent() instead of this handler. The latter handler is invoked when any movie clip receives data.

Example

The following example illustrates the correct use of MovieClip.onData() and onClipEvent(data):

// symbol_mc is a movie clip symbol in the library.
// It is linked to the MovieClip class.
// The following function is triggered for each instance of symbol_mc
//   when it receives data.
symbol_mc.onData = function() {
   trace("The movie clip has received data");
}
// dynamic_mc is a movie clip that is being loaded with MovieClip.loadMovie().
//   This code attempts to call a function when the clip is loaded, 
//   but it will not work, because the loaded SWF is not a symbol
//   in the library associated with the MovieClip class.
function output()
{
    trace("Will never be called.");
}
dynamic_mc.onData = output;
dynamic_mc.loadMovie("replacement.swf");
// The following function is invoked for any movie clip that
// receives data, whether it is in the library or not.
// Therefore, this function is invoked when symbol_mc is instantiated 
//    and also when replacement.swf is loaded.
OnClipEvent( data ) {
   trace("The movie clip has received data");
}

See also

onClipEvent()

Comments


KDmytro said on Oct 8, 2004 at 12:07 PM :
AS2 is case sensitive. So in the example above last lines on code should be:
onClipEvent( data ) {
instead of:
OnClipEvent( data ) {
_Vengeance_ said on Apr 6, 2005 at 9:07 AM :
I have a 1-frame blank movie clip that I use loadMovie to load an external SWF in.

Is there ANY WAY POSSIBLE to make our navigation pause button pause this loaded SWF? Otherwise, we have to take the button out...

My coworker insists it is impossible to tell the swf to stop, because it is actually a 1-frame movie clip that loads a swf at runtime, therefore the swf has no associated timelines or event handlers and such. is this right?

clint@acm.vt.edu
Fumio Nonaka said on Jun 5, 2005 at 2:14 AM :
MovieClip.onData has no way to be invoked when a MovieClip receives
data from a MovieClip.loadMovie() call.

If the event handler is defined to a target MovieClip to load an external
SWF, it will be cleared when the SWF is loaded. You cannot set the
handler to an external SWF before it is loaded.

You should use onClipEvent (data) handler on the target MovieClip
instead.
Thais Derich said on Jul 21, 2005 at 5:12 PM :
KDmytro-You are correct. OnClipEvent should be onClipEvent. I updated the source.

 

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

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001527.html