PDA

View Full Version : MX: How to load movie but keep same handler?



lowprofile
June 27th, 2003, 07:44 AM
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.

4. Then I load a different movie: root.contents.loadMovie("hardware.swf");

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

lowprofile
June 27th, 2003, 04:05 PM
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?

lowprofile
June 27th, 2003, 05:10 PM
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?

claudio
June 27th, 2003, 05:37 PM
Wat are you trying to achive?

kode
June 27th, 2003, 06:58 PM
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? =) :P

lowprofile
June 27th, 2003, 11:00 PM
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...

kode
June 28th, 2003, 03:06 AM
No problem, lowprofile. ;)

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