Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

onLoad.as

Name: onLoad - made to work
Author: senocular: www.senocular.com
Date: 
1899-12-31T00:21:36.900
Documentation:
read comments 

Example:
createEmptyMovieClip("hi", 1);
hi.onLoad = function() {
        trace("onLoad " + this + this._url);
};
hi.loadMovie("test.swf");

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// The following is for defining an onload in a frame script for a movieclip
// placed on the screen.  Note: if you define an onload AFTER it has loaded,
// the onload will be run immediately after defined and not again as it is called
// through an onenterframe as a workaround. NOTE: the following is for when NO
// onClipEvents have been defined for this movieclip.  Its only then when the 
// onLoad isnt recognised and this workaround is needed.

setEnterFrame = function(onEnterFrame_def){
	this._onEnterFrame = onEnterFrame_def;
}
getEnterFrame = function(){
	this.onLoad();
	delete this.onLoad;
	return this._onEnterFrame;
}
//redefine onEnterFrame using previous functions
MovieClip.prototype.addProperty("onEnterFrame", getEnterFrame, setEnterFrame);
// if onenterFrame is not defined but onload is
MovieClip.prototype.onEnterFrame = function(){
	this.onLoad();
	delete this.onLoad;
}

// The following maintains the onLoad after a movieClip is loaded
// into this clip using loadMovie
// credits:
// "bokel" <actionscript@bokelberg.de> 
// in context at http://chattyfig.figleaf.com/ezmlm/ezmlm-cgi?1:mss:49174

//setter for onLoad
sol = function (f){
        if(__onLoadHandler__ == undefined) _global.__onLoadHandler__ = {};
        __onLoadHandler__[this] = f;
};
//getter for onLoad
gol = function(){
        return __onLoadHandler__[this];
}
//assign property-handlers for onLoad (courtesy of Gnut)
MovieClip.prototype.addProperty("onLoad", gol, sol);