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:

http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm

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);
             trace(this);
}

so i tried this…


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

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:
http://www.kirupa.com/developer/oop/AS1OOPClassesWithMCs7.htm

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
stop();

//create the movie clip to hold the preloader
this.createEmptyMovieClip("preLoader_mc",1);
//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();
loadFormat.font="verdana";
loadFormat.bold=true;
loadFormat.size=8;
loadFormat.color=0xffffff;
preLoader_mc.loader_txt.setNewTextFormat(loadFormat);

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

preLoader_mc.onEnterFrame = function(){
	this.clear();
	//create the lineStyle
	preLoader_mc.lineStyle(0,0xFFFFFF,100);
	//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
		this.loader_txt.text=percentLoaded+"%";
		//start the fill
		this.beginFill(0x925080,100);
		//draw the loader
		this.moveTo(this.startX,this.startY);
		this.lineTo(this.startX,this.startY+8);
		this.lineTo(this.startX+(percentLoaded*2),this.startY+8);
		this.lineTo(this.startX+(percentLoaded*2),this.startY);
		this.lineTo(this.startX,this.startY);
		this.endFill();
	}else{
		//go to the second frame
		_root.play();
		//remove this preloader
		this.removeMovieClip();
		this.removeTextField();
	}
}

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: