flash actionscript:
Hi, I have successfully made a Preloader when my main SWF movie loads I don't know how to repeat this Preloader, each time a new SWF loads into an empy movie clip on my main SWF stage, called "screen_mc" All SWFs are loaded when a button is pressed in another empty movieclip on the main SWF called "text_mc" The functionality all works except I don't know how to code the Preloader to run each time a SWF loads any help is greatly appreciated
if you've set up a preload function then you can use setInterval() to repeatedly call your preload function whenever an external swf is loaded. for example: function preloadF(mc,ind){ loaded=mc.getBytesLoaded(); total=mc.getBytesTotal(); if(loaded>=total){ clearInterval(preloadI); // take some action possibly using the value of ind } } and attached to your buttons you would use: on(press){ myTarget.loadMovie("myswf.swf"); preloadI=setInterval(preloadF,100,myTarget,ind); }
I tried that, but it didn't work If you have a chance please, Here's my original code on Frame 1 of my Main SWF's Action Layer: //main.swf onLoad = function() { _root.createEmptyMovieClip("text_mc", 10); _root.createEmptyMovieClip("screen_mc", 20); } //Bio button loads text clip & bio movies bio_btn.onRelease = function() { loadMovie("bioScroll.swf", text_mc); } //Film button loads film text & ghostBOX movies film_btn.onRelease = function() { loadMovie("gBFilm.swf", text_mc); } //Motion graphics button loads text & Reel motion_btn.onRelease = function() { loadMovie("motion.swf", text_mc), loadMovie("motionGraphics.swf", screen_mc); } //Music Video button loads text & music video musicvideo_btn.onRelease = function() { loadMovie("musicVideo.swf", text_mc), loadMovie("Video.swf", screen_mc), screen_mc._y=405, screen_mc._x=585; } //preloader function checkLoad(mcTarget:MovieClip):Void{ //nLBytes stores the current bytes that have loaded var nLBytes:Number = mcTarget.getBytesLoaded(); //nTBytes stores the total bytes of the movie var nTBytes:Number = mcTarget.getBytesTotal(); //nPercent calculates the percent of the movie that //has loaded into the Flash player var nPercent:Number = (nLBytes/nTBytes)*100; //Apply the nPercent value to the X scale of the //mcBar instance within the mcLoader instance mcLoader.mcBar._xscale = nPercent; //Fill the tPercent field within the mcLoader instance //with the nPercent value followed by the text //"% of" and the total kilobytes of the movie. For //example, when half of a 64k movie has loaded, the text //field will display "50% of 64k loaded." var sPercent:String = Math.floor(nPercent).toString(); var sKBytes:String = Math.floor(nTBytes/1024).toString(); var sMessage:String = sPercent + "% of " + sKBytes + "K loaded."; mcLoader.tPercent.text = sMessage; //If the loaded bytes are greater than or equal to the //total bytes of the movie and the total bytes are //greater than 0 if (nLBytes >= nTBytes && nTBytes > 0) { //Check to see if the nCount variable is greater than //or equal to 12. If it is, execute the nested code. //This if/else code pauses the movie once 100% of the //movie has loaded into the Flash Player if (nCount >= 12) { //exit the loading sequence by removing the //setInterval ID established later in this frame clearInterval (nProgress); //jump to the "main" frame mcTarget.gotoAndStop("main"); // otherwise, if the movie has completely loaded and // nCount is less than 12. } else { //add 1 to the count variable nCount++; //continue executing the checkLoad() function with //setInterval(). There is no further code to insert //here, as this will happen automatically if //clearInterval() is not executed. } } //force the stage to refresh the screen independent of //the frame rate of the movie updateAfterEvent(); } //Initialize a count variable (to pause the loader briefly //at 100%) with a value of 0 var nCount:Number = 0; // As soon as this frame is played, start executing the //the checkLoad() function continuously, passing a //reference of the Flash movie (this) as an argument var nProgress:Number = setInterval(checkLoad, 100, this); //stop the Movie stop();
the only setInterval() that i see is preloading your main movie: var nProgress:Number = setInterval(checkLoad, 100, this); i thought you want to execute that preload code when movies are loaded in response to your button presses. if that's true, why didn' you add those setInterval()'s to the button presses as shown in my message above?
Don't see what you're looking for? Try a search.
|