Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Here is how to build a simple loader frame that waits for the entire movie to load before continuing past frame 1:
1. |
Start with a blank movie. |
2. |
Place a blank key frame at frame 1. Start a new key frame at frame 2. Play some content starting at frame 2 and continuing on. It should be at least 100K worth of content. A good way to get fast content is to import a video. |
4. |
Back at frame 1, we want to have the movie wait until the entire movie has been loaded before continuing to frame 2. Start by placing a stop() command on the frame. |
5. |
Create a simple shape, convert it to a movie clip, and move it off the screen. Assign this script to it:
onClipEvent(enterFrame) {
bytesLoaded = _root.getBytesLoaded();
bytesTotal = _root.getBytesTotal()
percentLoaded = Math.round(100*bytesLoaded/bytesTotal);
_root.displayText = "Loading: "+percentLoaded+"%";
if (bytesLoaded == bytesTotal) {
_root.play();
}
}
The script looks at getBytesLoaded to see whether the movie has finished loading; it uses this to also calculate the percent of the movie loaded. It places this number into the variable displayText at the root level. |
6. |
Create a dynamic text field and link it to the variable displayText. |
7. |
It will be difficult to test this movie on your hard drive because it will load too quickly. Instead, Publish it, complete with a Web page. Upload it to a test directory on your Web site. |
8. |