onClipEvent Handler

what’s the alternate solution to using an onClipEvent Handler? For example… I know that you would use the following script within a movie clip…

onClipEvent (load) {

but what if you wanted to do the same thing only your AS is not inside of the movie clip? Because I created my movie clip with AS instead(createEmptyMovieClip) and need to know how to load some files. I tried the .onLoad, but it’s not the same thing.

Thanks in advanced.

They are called Dynamic Event Handlers, very useful things, I love them. I never use onClipEvents anymore :smiley:


did you try this code on the frame you want to have it?

yourmc.onLoad = function(){
//load some files

edit: lostinbeta was just a little bit quicker… but he has the same answer

onLoad as a dynamic event handler is typically used for loading in external data (via the LoadVars() or XML() objects).

onLoad as a dynamic event handler for a movieclip is pretty much pointless since the clip must exist to be targetted anyway. So basically…

myClip.onLoad = function(){
    this._x = 500;

Is the same as saying…

myClip._x = 500

on the same frame. No need for the onLoad handler.

well i originally had something similar to this within a movie clip with instance of preloader_mc

onClipEvent (load) {	
	// create empty movie clips
	loadMovieNum ("movie_clips/clip.swf", 50);

so i tried this…

preLoader_mc.onLoad = function(){
	// create empty movie clips
	loadMovieNum ("movie_clips/clip.swf", 50);

well i’m assuming it’s not the same because the trace won’t work… am i just missing something? or can you just not do it this way?

preLoader_mx.loadMovieNum(“movie_clips/clip.swf”, 50);

should suffice (last post i mentioned using onLoad as a dynamic event handler is not neccessary)

[font=courier new]loadMovieNum()[/font] is a top-level function, not a method of the [font=courier new]MovieClip[/font] object. The code should read as follows:

loadMovieNum("movie_clips/clip.swf", 50);

And check out this link for more info on the [font=courier new]MovieClip.onLoad[/font] event handler, jiggavo:

yeah my apoligies… the comment i had in there was actually when i had a createEmptyMovieClip().

Thanks for clearing everything up guys.

okay… it’s still not working… my code is as follow

// stop the play head

//create the movie clip to hold the preloader
//put the preloader in the right spot
preLoader_mc._x = 242;
preLoader_mc._y = 212;
//create some variables for the preloader
preLoader_mc.tBytes = this.getBytesTotal();
preLoader_mc.startX = 0;
preLoader_mc.startY = 0;

//create the text field to display the information
preLoader_mc.createTextField("loader_txt", 10,176,-14,50,20);
//create a text format and set some properties
var loadFormat:TextFormat = new TextFormat();

// load external movies
preLoader_mc.loadMovieNum("movie_clips/clip.swf", 50);

preLoader_mc.onEnterFrame = function(){
	//create the lineStyle
	//get the amount of loaded bytes
	lBytes = _root.getBytesLoaded();
	//create the percentage variable
	var percentLoaded = Math.floor((lBytes/this.tBytes)*100);
	if(lBytes != this.tBytes){
		//insert the text into the text field
		//start the fill
		//draw the loader
		//go to the second frame
		//remove this preloader

the entire script iteslf works… but it’s not loading the external movie.

LOL - What did I just say in my previous post? :wink:

// load external movies
loadMovieNum("movie_clips/clip.swf", 50);

sigh sorry kode, got it to work now. thanks for your patience.

Sure - No problem. :slight_smile: