Skip to main content
Participating Frequently
May 27, 2006
Question

JPG LoadMovie events?

  • May 27, 2006
  • 5 replies
  • 765 views
Please help me with this...

This works:

this.createEmptyMovieClip("box_mc", 100);
box_mc._x = 32;
box_mc._y = 32;
with (box_mc) {
lineStyle(1, 0xCCCCCC);
beginFill(0xEEEEEE);
moveTo(0, 0);
lineTo(80, 0);
lineTo(80, 60);
lineTo(0, 60);
lineTo(0, 0);
endFill();
};
box_mc.onPress = function() {
this._x -= this._width/2;
this._y -= this._height/2;
this._xscale = 200;
this._yscale = 200;
};
box_mc.onRelease = function() {
this._xscale = 100;
this._yscale = 100;
this._x += this._width/2;
this._y += this._height/2;
};

This does not work:

this.createEmptyMovieClip("box_mc", 100);
box_mc._x = 32;
box_mc._y = 32;
with (box_mc) {
loadMovie("smiley.jpg");
};

box_mc.onPress = function() {
this._x -= this._width/2;
this._y -= this._height/2;
this._xscale = 200;
this._yscale = 200;
};
box_mc.onRelease = function() {
this._xscale = 100;
this._yscale = 100;
this._x += this._width/2;
this._y += this._height/2;
};

WHY NOT??!?
This topic has been closed for replies.

5 replies

Inspiring
May 28, 2006
Cool. With MX04, you can use the MovieClipLoader which is IMHO much easier, but understanding the concept behind the old-school preloader is (again IMHO) a very important skill for understanding Flash.

I would add one thing to juankpro's (much nicer than mine) code. Notice in mine that part of the condition is to check the _width of the clip as well as the bytesLoaded and bytesTotal. In rare cases (probably not this example) and with certain browsers and versions of Flash player (in other words, in really hard to repeat and yet maddeningly troublesome cases) your loaded clip won't actually be available until the _width is greater than zero even though the bytes have completely loaded.

It is kind of the old-school equivalent of the issues surrounding the use of onLoadInit instead of onLoadComplete.

Good luck!
Inspiring
May 28, 2006
Well that would be your problem right there! The MovieClipLoader class wasn't introduced until Flash 7. Also the help files before version 7 were absolutely awful so that was why it didn't explain the part I mentioned.

You will have to make your own preloader code that checks to see when the clip has fully loaded. This is something you should learn anyways for so many reasons.

Basically you need to repeatedly check to see if the clip is completely loaded. So here is a basic example.

this.createEmptyMovieClip("holder",1000);
holder.loadMovie("somefile.swf");
this.onEnterFrame=function(){
var bT=holder.getBytesTotal();
var bL=holder.getBytesLoaded();
if(bT==bL && holder._width>0){
//it is now loaded and you can do what you would like:
delete this.onEnterFrame;
}
}

I think that is it. I just typed it from memory so I might have made a mistake. And it is very basic, but might give you the general idea. Try it in a brand-new simple file before you try and work it into your current project.

PS: And if you can, upgrade your copy of Flash!
Inspiring
May 28, 2006
Assign thiis to the clip into which the new clip is going to be loaded.
Beachie1Author
Participating Frequently
May 28, 2006
quote:

Originally posted by: juankpro
Assign thiis to the clip into which the new clip is going to be loaded.
There's the problem though - I'm creating the clip(s) dynamically with createemptymovieclip, so I can't attach an event.

Inspiring
May 28, 2006
Then you must attach the code after loading and not before.For this use the MovieClipLoader object or an onEnterFrame poll function:

MovieClipLoader:
You create a MovieClipLoader then a listener for events, register this listener as the listener for the loader. When the jpg file is loaded the onLoadInit event executes and then you can attach the methods. The loadClip method load the clip on the first parameter to the clip on the second parameter.



Inspiring
May 28, 2006
The problem is that when you load movies the event handlers like onPress and onReleased are erased to be replaced for the versions used by the loaded movie. Becuase the loaded movie doen't have them aoriginally then they are just erased.
Beachie1Author
Participating Frequently
May 28, 2006
quote:

Originally posted by: juankpro
The problem is that when you load movies the event handlers like onPress and onReleased are erased to be replaced for the versions used by the loaded movie. Becuase the loaded movie doen't have them aoriginally then they are just erased.
Thanks for your reply The help mentions using onClipEvent() or on() but I'm not sure how I can assign one of these to a loaded movie..

Inspiring
May 27, 2006
You might want to read the help files for MovieClip.loadMovie(); paying particular attention to the paragraph that begins with. "Using event handlers with MovieClip.loadMovie() can be unpredictable."
Beachie1Author
Participating Frequently
May 28, 2006
quote:

Originally posted by: Rothrock
You might want to read the help files for MovieClip.loadMovie(); paying particular attention to the paragraph that begins with. "Using event handlers with MovieClip.loadMovie() can be unpredictable."
Thankyou! Oddly enough, my help mentions nothing about that, but I've tracked it down on the macromedia site..