# MX: How to load movie but keep same handler?

**URL:** <https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219>\
**Category:** flash\
**Created:** [June 27, 2003, 11:44am UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219 "2003-06-27T11:44:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lowprofile](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@lowprofile](https://forum.kirupa.com/u/lowprofile)\
**Post date:** [June 27, 2003, 11:44am UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/1 "2003-06-27T11:44:53Z")

</div>

Hi,  
I have a blank movie in a library

1. I drop it on the stage.
2. I name the instance “content”
3. I use some code to detect an event : onClipEvent(mouseDown)  
content.onMouse…

Everything works.

1. Then I load a different movie: root.contents.loadMovie(“hardware.swf”);

2. Now my handler from #3 doesn’t work, it can’t do content.onMouse…

How can I set something…? variable? so that when the blank movie clip is loaded with different movies I can name it to “content” to still use the original eventhandler so that #3 above still works?

Thanks

---

<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:** [June 27, 2003, 8:05pm UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/2 "2003-06-27T20:05:59Z")

</div>

Anyone know ?

There must be some way for keeping the handler name so that you can have your code refer to the same blank movie clip instance name?

---

<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:** [June 27, 2003, 9:10pm UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/3 "2003-06-27T21:10:28Z")

</div>

I have heard that apparently because MX NOW (not in version 5) wipes out every event related to the movie clip when you use a movieload.  
Anyone know how to make the new movie clip reload its event handlers?

---

<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:** [June 27, 2003, 9:37pm UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/4 "2003-06-27T21:37:23Z")

</div>

Wat are you trying to achive?

---

<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:** [June 27, 2003, 10:58pm UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/5 "2003-06-27T22:58:09Z")

</div>

After a few minutes of coding, two cigarettes and a beer… this is what I came up with:

```auto
ASBroadcaster.initialize(MovieClip);
this.createEmptyMovieClip("$OEF", 9876);
$OEF.onEnterFrame = function() {
	MovieClip.broadcastMessage("onEnterFrame");
};
MovieClip.prototype.$loadMovie = MovieClip.prototype.loadMovie;
MovieClip.prototype.loadMovie = function(url) {
	var propObj = new Object(), prop;
	for (prop in this) {
		propObj[prop] = this[prop];
	}
	this.$loadMovie(url);
	var preloader = new Object(), clip = this, loaded;
	preloader.onEnterFrame = function() {
		if (clip.getBytesLoaded() && clip.getBytesLoaded() == clip.getBytesTotal()) {
			if (loaded) {
				for (prop in propObj) {
					clip[prop] = propObj[prop];
				}
				MovieClip.removeListener(this);
				delete this.onEnterFrame;
			}
			loaded = true;
		}
	};
	MovieClip.addListener(preloader);
};
ASSetPropFlags(MovieClip.prototype, null, 1);
// test
this.createEmptyMovieClip("myClip", 0);
myClip.onMouseMove = function() {
	this._alpha = Math.random()*100;
};
myClip.loadMovie("http://www.kirupaforum.com/swf/wh.swf");

```

… Does that help? =) 😛

---

<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:** [June 28, 2003, 3:00am UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/6 "2003-06-28T03:00:13Z")

</div>

Thanks kax !!!

I have a different one I found and made work, it recalls the onload, and ondata events - and inside onload I just dynamically assigned the onmouseevent handler again.

Going to look at yours now. Looks more complex.  
What is with the ASBroadcaster and stuff…

---

<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:** [June 28, 2003, 7:06am UTC](https://forum.kirupa.com/t/mx-how-to-load-movie-but-keep-same-handler/24219/7 "2003-06-28T07:06:13Z")

</div>

No problem, lowprofile. 😉

[http://www.umbc.edu/interactive/flash/tutorials/showpage.php?p=ASBroadcaster](http://www.umbc.edu/interactive/flash/tutorials/showpage.php?p=ASBroadcaster)
