View comments | RSS feed

MovieClip.onUnload

Availability

Flash Player 6.

Usage

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

Parameters

None.

Returns

Nothing.

Description

Event handler; invoked in the first frame after the movie clip is removed from the Timeline. Flash processes the actions associated with the onUnload event handler before attaching any actions to the affected frame. 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.

Example

The following example defines a function for the MovieClip.onUnload method that sends a trace() action to the Output panel:

my_mc.onUnload = function () {
   trace ("onUnload called");
};

Comments


Fumio Nonaka said on Sep 1, 2004 at 1:12 PM :
'MovieClip.onUnload' event handler is not called when the MovieClip
instance is deleted with 'MovieClip.removeMovieClip()' method from
within the callback function of 'setInterval'. However the event is
triggered with 'MovieClip.unloadMovie()' method. It is not invoked when
the instance is disappeared by going to a frame where it does not exit,
too.

// _root
// Frame action
// _root.my_mc is placed
my_mc.onUnload = function() {
trace("unload");
};
nID = setInterval(xClearMovieClip, 1000);
function xClearMovieClip() {
// my_mc.unloadMovie(); // calls unload
// my_mc does not exist in the next frame
// _root.nextFrame(); // does not call unload
my_mc.swapDepths(1);
my_mc.removeMovieClip(); // does not call unload
}
this.stop();

If the MovieClip is removed from a Button, MovieClip or frame actions,
'MovieClip.onUnload' is triggered. It does not seem to be called when
the MovieClip is removed from within some callback functions. The
same issue is reproduced when the callback function is set to a
LoadVars or XML instance.
No screen name said on Dec 5, 2004 at 3:59 PM :
I disagree. The MovieClip.onUnload() is triggered if the instance is
disappearing by going to a frame where it does not exist, but
unfortunately after the MovieClip is gone. It seemed therefore you can't
read properties frome the MovieClip anymore - for example to backup
variables populating the clip.
meni56 said on Mar 8, 2005 at 7:44 AM :
Fumio Nonaka is 100% right!
When i do MovieClip.onUnload = function () {
trace ("onUnload called:"+this);
}
nothing happend
the MC is in last secena in the swf and i put this cose at first secena in first frame
FlashConference said on May 16, 2005 at 10:13 AM :
I make unload file. It's very easy :-)

// onUnloadTest.as
class onUnloadTest extends MovieClip
{
function onUnloadTest()
{
this.onLoad = this.initial;
}
function onPress()
{
this._x += 20;
if (this._x>400)
{
trace("400보다크다");
this.removeMovieClip();
//this._visible = false;
}
}
function initial()
{
trace("this = "+this);
this._x = 125;
this._y = 100;
}
}
// onUnload.fla - flash document(main)
// this fils have to Library Linkage circle symbol... stage is empty..
this.attachMovie("circle", "circle", 1);
circle.onUnload = function()
{
trace("unload")
_level.unload_check.text = "unload 이벤트 발생"
}
// unload_check is dynamic textfield...


enjoy~... :-)



I'm from your friendsofed U-Fc(Adam)
www.flashconference.co.kr(soon)
www.nfmk.com
www.ysbn200.com

 

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/00001544.html