# onClipEvent Handler

**URL:** <https://forum.kirupa.com/t/onclipevent-handler/59393>\
**Category:** flash\
**Created:** [July 30, 2004, 9:48pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393 "2004-07-30T21:48:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiggavo](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jiggavo](https://forum.kirupa.com/u/jiggavo)\
**Post date:** [July 30, 2004, 9:48pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/1 "2004-07-30T21:48:13Z")

</div>

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…

```auto

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 9:51pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/2 "2004-07-30T21:51:33Z")

</div>

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

[http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm](http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 9:51pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/3 "2004-07-30T21:51:49Z")

</div>

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

```auto

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

```

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 9:55pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/4 "2004-07-30T21:55:47Z")

</div>

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…

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

```

Is the same as saying…

```auto
myClip._x = 500

```

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 10:49pm UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/5 "2004-07-30T22:49:59Z")

</div>

well i originally had something similar to this within a movie clip with instance of **preloader\_mc** …

```auto

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

```

so i tried this…

```auto

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 12:05am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/6 "2004-07-31T00:05:54Z")

</div>

preLoader\_mx.loadMovieNum(“movie\_clips/clip.swf”, 50);

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 12:19am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/7 "2004-07-31T00:19:29Z")

</div>

[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:

```auto
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](http://www.kirupa.com/developer/oop/AS1OOPClassesWithMCs7.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 1:18am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/8 "2004-07-31T01:18:36Z")

</div>

> [@kode](#):
>
> [font=courier new]loadMovieNum()[/font] is a top-level function, not a method of the [font=courier new]MovieClip[/font] object.

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

Thanks for clearing everything up guys.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 1:50am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/9 "2004-07-31T01:50:14Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 5:10am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/10 "2004-07-31T05:10:47Z")

</div>

> [@jiggavo](#):
>
> ```auto
> // load external movies
> preLoader_mc.loadMovieNum("movie_clips/clip.swf", 50);
> 
> ```

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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 5:43am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/11 "2004-07-31T05:43:18Z")

</div>

> [@kode](#):
>
> LOL - What did I just say in my previous post? 😉
> 
> ```auto
> // load external movies
> loadMovieNum("movie_clips/clip.swf", 50);
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 31, 2004, 6:50am UTC](https://forum.kirupa.com/t/onclipevent-handler/59393/12 "2004-07-31T06:50:43Z")

</div>

Sure - No problem. 🙂
