Yes, by now we should all know that Flash MX can load .jpg files dynamically into a flash movie aswell as being able to load external .swf files, but as always, when it comes to loading large files from external sources, it is good practice and almost standard to create a preloader for the file. The Flash MX Event Model knowledge. The Macromedia Flash Help Files 'forgot' to mention that when you are loading an external movie or an external image into a Movieclip, that the Movieclip is reset or emptied of all its contents, this means that all properties, methods, child movieclips and event handlers assigned inside of that Movieclip are deleted and no longer exist. Once again, remember that levels are also movieclips, _level0 (root timeline) is classed as a Movieclip. Therefore loading an external image or external movie into _level0 using the loadMovieNum function will delete all of the contents of your main movie:
Found an error or have a suggestion? Let us know and we'll review it.
loadMovieNum("http://www.relevare.com/site/main_noo.swf",0);
This can cause problems when it comes to creating preloaders for external movies and external images.
After reading the Macromedia Flash MX Actionscript Manual, i would expect the above code to output the words "Data was recieved" everytime a piece of the Macromedia Global Navigation swf file had downloaded into the movie, but because of the drawbacks i explained previously it doesnt. The Movieclip.onData event handler is deleted when the loadMovieNum function is called, therefore you cannot use the Movieclip.onLoad event handler to create a preloader for a loaded movie or a loaded image. The same problem occurs when using the Movieclip.onLoad event handler, according to the the Macromedia Flash MX Actionscript Manual, the Movieclip.onLoad event handler should fire when an external image or external movie has finished loading into the Movieclip which the Movieclip.onData event handler resides. Again, this is so not true, and two lines of code to prove that claim aswell:
this.onLoad=function(){
  
trace("Movie was loaded");
}
loadMovieNum("http://www.macromedia.com/uber/nav/global_home.swf",0);
I would expect the above code to output the words "Movie was loaded" when the Macromedia Global Navigation swf had completley downloaded into the Movieclip, but no, it doesnt output anything, because the Movieclip.onLoad event handler is deleted when the loadMovieNum function is called. Because of these drawbacks, you will have to use the Movieclip.onEnterFrame event handler of a Movieclip other than the Movieclip which is having either an external movie or an external image loaded into it, to create a preloader:
//create a new movieclip to load
//the external movie into
this.createEmptyMovieClip("holder",1);
//load the external movie into the new movieclip
holder.loadMovie("http://www.macromedia.com/uber/nav/global_home.swf");
//check the download status of the external
//movie once every frame
this.onEnterFrame=function(){
  
//trace the percentage of the movie that has loaded
  
percent=(this.holder.getBytesLoaded()/this.holder.getBytesTotal())*100;
  
if(!isNan(percent)){
   
trace(percent+"% loaded");
  
}else{
   
trace("0% loaded");
  
}
  
if(percent == 100){
   
delete this.onEnterFrame;
   
}
}
You can also fix this bug, by placing this code on the first frame of your Flash Movies:
_global.s_onLoad=function(f)
{
  
if(onLoadManager == undefined)
  
{
   
_global.onLoadManager={};
  
}
  
onLoadManager[this] =f;
}
_global.g_onLoad=function()
{
  
return onLoadManager[this];
}
_global.s_onData=function(f)
{
  
if(onDataManager == undefined)
  
{
   
_global.onDataManager={};
  
}
  
onDataManager[this]=f;
}
_global.g_onData=function()
{
  
return onDataManager[this];
}
MovieClip.prototype.addProperty("onLoad", g_onLoad, s_onLoad);
MovieClip.prototype.addProperty("onData", g_onData, s_onData);
Thanks to Bokel @ FlashCoders, for sharing this fix.
Guy Watson (or FlashGuru as he is also known) has been an active, well
recognized figure in the Flash community for over four years,
supporting the community with tutorials, source files, moderating the
Flashkit forums, and running his own Flash resource Web site,
FlashGuru's MX 101. Guy was one of two developers who created the ever
popular, award winning zoom interface for Relevare and now runs his
own company,
Suggest a Correction
Movie & Image Preloader Woes
0 views
Comments (0)
Please sign in to leave a comment.





No comments yet. Be the first to comment!