View comments | RSS feed

onLoadInit (MovieClipLoader.onLoadInit event listener)

onLoadInit = function([target_mc:MovieClip]) {}

Invoked when the actions on the first frame of the loaded clip have been executed. When this listener has been invoked, you can set properties, use methods, and otherwise interact with the loaded movie. Call this listener on a listener object that you add by using MovieClipLoader.addListener().

The value for target_mc identifies the movie clip for which this call is being made. This parameter is useful if you are loading multiple files with the same set of listeners.

Availability: ActionScript 1.0; Flash Player 7

Parameters

target_mc:MovieClip [optional] - A movie clip loaded by the MovieClipLoader.loadClip() method.

Example

The following example loads an image into a movie clip instance called image_mc. The onLoadInit and onLoadComplete events are used to determine how long it takes to load the image. This information is displayed in a text field called timer_txt.

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
    target_mc.startTimer = getTimer();
};
mclListener.onLoadComplete = function(target_mc:MovieClip) {
    target_mc.completeTimer = getTimer();
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
    var timerMS:Number = target_mc.completeTimer-target_mc.startTimer;
    target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(), 0, target_mc._height, 
target_mc._width, 22);
    target_mc.timer_txt.text = "loaded in "+timerMS+" ms.";
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", image_mc);

The following example checks whether a movie has loaded into a movie clip created at runtime. The URL used in this example is for demonstration purposes only; replace it with your own valid URL.

this.createEmptyMovieClip("tester_mc", 1);
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
    trace("movie loaded");
}
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("http://www.yourserver.com/your_movie.swf", tester_mc);

If your SWF file includes a version 2 component, use the version 2 component's DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.

See also

addListener (MovieClipLoader.addListener method), loadClip (MovieClipLoader.loadClip method), onLoadStart (MovieClipLoader.onLoadStart event listener)


Version 8

Comments


rollingsj said on Nov 14, 2005 at 2:13 PM :
It seems the onLoadInit method would be helpful in centering a loaded movieClip or image within the holder movieClip. While this does work, and we do have access to the properties of the loaded clip, there does not appear to be a way to successfuly hide the clip while it is being centered. Setting either the _alpha or _visible properties does not help the situation because we have no way to telling when the clip has been rendered corectly on screen, and therefore have to trigger for which to unhide it.
asem03 said on Nov 29, 2005 at 8:40 AM :
Can we use the onLoadProgress, onLoadinit, ... the listener functions, that way:

class com.MyClass extends MovieClip{
public var mclLoader:MovieClipLoader;
public var oListener:Object;

public function MyClass(){
init();
}

public function init(){
mclLoader = new MovieClipLoader();
oListener = new Object();
oListener.onLoadInit = initLoad;
oListener.onLoadProgress = progressLoad;
oListener.onLoadComplete = completeLoad;
oListener.onLoadError = errorLoad;
mclLoader.addListener(oListener);
}

public function initLoad(targetMc:MovieClip){
}

public function progressLoad(targetMc:MovieClip, bytesLoaded:Number, bytesTotal:Number){
}

public function completeLoad(targetMC:MovieClip, nHttpStatus:Number){
}

public function errorLoad(targetMc:MovieClip, errorCode:String, httpStatus:Number) {
}

}

This syntaxe doesn't seem to work.
When can we use this kind of function declaration and when can't we ?

objet.function = otherfunction;

thx
Laurent
djtechwriter said on Dec 14, 2005 at 2:43 PM :
Laurent,

I think you're combining two different approaches to event handling. You are using the syntax for event handling with the listener-broadcaster model. So, you should be able to use something similar to the following syntax instead:

mclLoader = new MovieClipLoader();

mclLoader.onLoadInit = initLoad;
mclLoader.onLoadProgress = progressLoad;
mclLoader.onLoadComplete = completeLoad;
mclLoader.onLoadError = errorLoad;


where:

broadcasterobject.event = otherfunction;

Or, you could try using the code you already have with the following (lengthy) syntax:

oListener.onLoadInit = function() {
initLoad();
};

...etc.

where:

listenerobject.event = function() {
otherfunction();
};
emu604 said on Mar 20, 2006 at 7:47 AM :
I know we can get the width and height of the loaded movie after onLoadInit is called, but in many cases it would be preferable to get the *STAGE* width & height of the loaded movie. Is there any way to access this information?
gothats said on May 7, 2006 at 11:53 AM :
rollingsj:
I know your post was a while ago, but I found a workaround.
In the onLoadStart listener, you can set the movieclip to _visible=false, then in the onLoadInit listener, set it's position and then at the end make it visible again.
jeffbruce said on Jun 16, 2006 at 3:40 PM :
According to the doc, the onLoadInit event fires:
"when the actions on the first frame of the loaded clip have been executed". I interpret that to mean that when loading a movie, once the first frame content is downloaded, and after any first frame AS executes, the event fires right away. Yet, in practice it seems like the event fires long after any AS on frame 1 executes. It does eventually fire for me, but sometimes not until *after* onLoadComplete!

If my interpretation of the desired behavior is incorrect, the documentation needs some work. If my interpretation is correct, then there appears to be a bug.
MosCD said on Aug 3, 2006 at 4:08 AM :
it seems like when using the onLoadInit method , the method is invoked even before the entire clip is laoded and rendered on screen and then once again when the actions on the first frame of the loaded clip have been executed ... does that seem to be a bug?
Christian Giordano said on Nov 10, 2006 at 4:56 AM :
You are right, jeff, it is wrongly, according to the documentation, triggered after onLoadComplete :S
That's a big shame IMHO.
No screen name said on Nov 21, 2006 at 4:34 AM :
Well,hello there!!!

I have a console (main movie) which loads external swfs (using
movieClipLoader)

In each ext. swf there is a function (placed in the 1st frame)
which is called from the console on user demand.
This works fine...But is some cases, I have to call the function
as soon as the swf has completly loaded (onLoadInit or onLoadComplete) and this dosent' works!

The function calls soundObject.start(0,5).The sound is attached to the movieclip from the library.

Any ideas???
No screen name said on Dec 8, 2006 at 6:09 PM :
hi, i am using loadMovie and loadClip to load an external swf which contains code to response to onMouseMouse events. if i use loadMovie and the swf is loaded it responds to mouse events on the listener mc. on the other hand if i use loadClip, the mc on the swf doesnt respond to the hit test. the odd think is that it responds if i remove the listener object from the movie clip loader before onLoadInit is called. what is the change caused by the call of the onLoadInit from the loader swf?
ElelphentTrunk said on Feb 5, 2007 at 2:14 PM :
onLoadInit (MovieClipLoader.onLoadInit event listener) clarification

onLoadInit will fire when all frames have completed loading, on the same or 1 frame after where onLoadComplete has fired, and after all the actions on that frame. This frame, in many cases, might NOT be the first frame depending on how much, how big(data size), and on what frames there is content. This is because, if the movie being loaded has many frames, flash will immediately begin playing it even if all its frames have not completely loaded.

The real gripe here is that there is almost no difference between onLoadComplete and onLoadInit, you could almost use them synonymolsly. Besides the one frame difference(which doesn't always happen for me), I can only think of property access as a potential problem, but I haven't tested that yet. Based documentation alone, this could be bug or just bad docuentation.

If you want onLoadInit to fire directly after the actions on the first frame you either have to put a stop action on the first frame of the movie you're loading or do something similar to the following:


this.createEmptyMovieClip("clip", 2);

mcl = new MovieClipLoader();

mcl.onLoadComplete = function() {
clip.gotoAndStop(1);
trace('olc ' + clip._currentframe);
}

mcl.onLoadStart = function() {
clip.stop();
trace('ols ' + clip._currentframe);
}

mcl.onLoadInit = function(s) {
trace('oli ' + clip._currentframe);
}

mcl.loadClip('loadee.swf', clip);


if you don't put clip.gotoAndStop(1) on onLoadComplete your loaded movie will end up on frame zero, which has no content and will seem like nothing loaded.

Hopefully this answers some questions for people. Sorry if I confused anybody, I'm not that great at explaining things.
yahdivad said on Feb 6, 2007 at 10:56 PM :
Adobe, I tried using your code:

mclLoader = new MovieClipLoader();
mclLoader.onLoadInit = initLoad;

in a class and it's throwing
"There is no property with the name 'onLoadInit'"
It's been driving me crazy, I need 2 mcls in the same class, I don't want to resort to using the class as a listener as I usually do but with 1 mcl using onLoadComplete.
Holoville said on Mar 3, 2007 at 4:04 PM :
onLoadInit is NEVER invoked if using local files within a Flash executable.

Plus, there is a somewhat different load process. Let's take we have a movieClipLoader which loads stuff inside a movieClip called "swapper". Inside the browser or the debug Flash environment, the process is:
- swapper is unloaded (because the externally loaded data resets it)
- calls to onLoadStart, onLoadProgress, unto onLoadInit are executed
If using a Flash executable instead, "swapper" is unloaded AFTER onLoadComplete event, while onLoadInit is never called...

Daniele
valderama2 said on Apr 25, 2007 at 4:06 AM :
I experienced strange behaviour with onLoadInit:

I load a jpeg with a MovieClipLoader and resize it in onLoadInit() after getting the real size of the jpeg.

I have the problem that for every other jpeg I load within the same frame and the same movieClip, I get wrong size information!

I've tried a lot, including not setting a mask on the movieClip and unloading the old Clip before loading the new. nothing helped..

maybe someone in here has an idea?

 

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