Skip to main content
Known Participant
September 18, 2010
Answered

How i can add to an preloader some external swf

  • September 18, 2010
  • 2 replies
  • 1114 views

Helo, i have this preloader:

onClipEvent (load) {

total = _root.getBytesTotal();

}

onClipEvent (enterFrame) {

loaded = _root.getBytesLoaded();

percent = int(loaded/total*100);

text = percent+"%";

gotoAndStop(percent);

if (loaded == total) {

_root.gotoAndPlay(2);

}

}

and on a movie clip with the name all pages in frame 6 i load some swf files with this way:
swf_path="mysongs.swf"
loadListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void  {
info.text = Math.round((bytesLoaded/bytesTotal)*100)+"%";
};
loadListener.onLoadInit = function(target_mc:MovieClip):Void  {
info.text = "";
};
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
mcLoader.loadClip(swf_path, swf_loader);
How i may preload those files too with the preloader? Is it safe to just use the code from the frame 6 inside the preloader?

This topic has been closed for replies.
Correct answer kglad

i cant change my preloader to load also the other swf's?i have to have 2 of them?

Also in your code i dont see where i put the swf path


you don't need two preloaders but it will be more complicated to use one preloader to load both an external file and your main swf.   again, give your preloader an instance name (eg, preloader_mc), remove all code attached to it, in an array, list all the swfs you want to load and display in your preloader (except your main swf):

var tl:MovieClip=this;

var swfA:Array = [swf_path1,swf_path2,...];

// create your load targets swf_loader1, swf_loader2 etc

var loadIndex:Number=0;

function loadF(){

clearInterval(preloadI);

preloadI=setInterval(loadProgress,500);

tl["swf_loader"+(loadIndex+1)].loadMovie(swfA[loadIndex]);

function loadProgressF(){

var f1:Number = tl["swf_loader"+(loadIndex+1)].getBytesLoaded()/tl["swf_loader"+(loadIndex+1)].getBytesTotal();

var f:Number = (f1)/(swfA.length+1)+loadIndex/(swfA.length+1)+tl.getBytesLoaded()/(tl.getBytesTotal()*(swfA.length+1));

percent = Math.round(f*100);
preloader_mc.text=percent+"%";

preloader_mc.gotoAndStop(percent);

if(f1>=1){

loadIndex++;

if(loadIndex<swfA.length){

loadF();

} else {

if(tl.getBytesLoaded()>=tl.getBytesTotal()){

clearInterval(preloadI);

}

}

}

}

2 replies

kglad
Community Expert
Community Expert
September 18, 2010

you can reuse your preloader movieclip IF there's no code attached to it.  assign it an instance name (eg, preloader_mc) and place it in the frame with your moviecliploader.  you can then use:

loadListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void  {
percent = Math.round((bytesLoaded/bytesTotal)*100);
preloader_mc.text=percent+"%";
preloader_mc.gotoAndStop(percent);
};
Known Participant
September 19, 2010

i dont want the preloader to be in the same frame with movieclip, i want in the first page to load all the swf that exist in other pages. The preloader bar has the code i have enter, im not sure what do you mean if there isnt any code inside

kglad
Community Expert
Community Expert
September 19, 2010

the preloader has to be in the same frame with that mcl code.  if you want that in the first frame, then put it your first frame but you'll need to do something so users know one preloader is loading the main swf and the other is preloading an external swf.

kglad
Community Expert
Community Expert
September 18, 2010

what's the problem?

Known Participant
September 18, 2010

how i can preload the mysongs.swf with my preloader