Flash Training: Preloading SWF & JPEG Files

HomeTutorialsForumWebwasp MembersTemplatesMatesFoodContact

 


Flash Tutorials

   

Flash Tutorial - Preloading External Jpegs or SWFs

Free Flash Tutorial


Step 5    <<   Previous      Intro   1   2   3   4   5    >>       >>   Webwasp Mates

 

Step Five: Adding the ActionScript

  1. In the Timeline click on the Insert Layer Button:
  2. Rename this new Layer: ActionScript
  3. On frame 1 of this new Layer add the following ActionScript (if you wish you may leave out the gray code hints):

// Create a listener object event function. The progress bar is an object so it needs an object function to work
myProgressBarListener = new Object();

// When the progress bar is complete and has preloaded the loader component content, the listener will call and run this code below:
myProgressBarListener = function (eventObject) {

// Hide the progress bar now as we don’t need it any more
myProgressBar._visible = false;

// Closes the above function
};

// Sets whether the content being loading into the loader component scales to fit the loader (true), or the loader scales to fit the content (false)
myLoader.scaleContent = true;

// Set the location of the content to be loaded. Examples are:
// myLoader.contentPath = "http://www.YourWebSite.com/images/myImage.jpg";
// myLoader.contentPath = "http://www.YourWebSite.com/myFlashMovie.swf";
myLoader.contentPath = "http://www.webwasp.co.uk/images/Sea.jpg";

// Declares a listener that detects when the progress bar component has loaded the loader component content and is complete. Then calls the function myProgressBarListener
myProgressBar.addEventListener("complete", myProgressBarListener);

// Set up the progress bar component variable to polled mode which determines the maths behind the % counter.
myProgressBar.mode = "polled";

// The location of the Loader Component
myProgressBar.source = "myLoader";

// Sets the conversion to 1. This basically means the component divides the current and total values loaded and to be loaded. Then it floors them (works out the difference between them) and displays the converted value in the label property
myProgressBar.conversion = "1";

// Set the label to display the word 'loading' followed by the percentage value loaded so far
myProgressBar.label = "LOADING %3%%";

// The direction the progress bar moves when loading
myProgressBar.direction = "right";

// The location of the label that displays the percentage loaded so far
myProgressBar.labelPlacement = "bottom";

// Stops the Playhead in the current frame until the Movie has been preloaded
stop();



Note:
For addition notes on what Macromedia have to say about the some of the Keywords used in the above ActionScript:

 

Important Note: Do not save your Jpeg images as Progressive. Progressive Images do not load into Flash Movies. You can find the Progressive Image setting in the save dialog box of your image editor such as PhotoShop (or similar).

 

That's it!!

 

Please indicate what you thought of this tutorial 
10 is the best: 
10 9 8 7 6 5 4 3 2 1

         

Step 5    <<   Previous      Intro   1   2   3   4   5    >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

252431 visitors to this page since Sept 05 •

Phil Schulz's Facebook profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.