MX: How to load movie but keep same handler?

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

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?

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?

Wat are you trying to achive?

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

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? =) :stuck_out_tongue:

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…

No problem, lowprofile. :wink:

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