When Flash movies are played back over the Internet, they stream, meaning that the plug-in shows as much of the movie as it can during download, even if the whole file has not been transferred to the user’s system or browser cache. The benefit of this feature is that users start seeing content without having to wait for the entire movie to finish downloading.
Nevertheless, streaming has potential drawbacks. First, during streamed playback, the movie may unexpectedly halt at arbitrary points on the timeline because a required portion of the movie has not yet downloaded. Second, ActionScript code is ignored when it refers to segments of the movie that have not downloaded. These drawbacks can lead to unpredictable and often undesired playback results.
Thankfully, there’s a solution. You can regulate the playback of the movie by using ActionScript code to prevent the movie from playing until a specified portion of it has downloaded. This technique is often referred to as preloading. A common preload sequence, or preloader involves displaying only a short message, such as “Loading . . . Please Wait,” while the movie loads. Once the appropriate amount of the movie has been retrieved, the movie is allowed to play. Flash 5 provides basic and advanced methods of producing a preloader. This section shows you how to use three different actions (or methods) to check the download status of a Flash movie:
Building a basic preloader with ifFrameLoaded
In this example, we explain how to create a preloader for a 100-frame movie, where the movie doesn’t begin playing until all 100 frames have been downloaded. For this exercise, make sure the Actions Panel is in Normal Mode.
Add content to the Main Timeline that will be preloaded.
Choose the Frame Label option of the Type setting, and then select begin_ movie from the Frame drop-down menu. Then check the Go to and Play option at the bottom of the parameter area. This Go To action, which starts playback of the real movie, will only be executed if the frame labeled minimum_loadpoint has been downloaded.
The ifFrameLoaded action is a one-time check. If the frame specified in ifFrameLoaded action has already downloaded, then the action(s) contained within the ifFrameLoaded statement are executed. If, on the other hand, the frame specified has not yet downloaded, then the action(s) contained are not executed, and the movie simply continues playing. In most cases, however, you won’t want the movie to carry on playing until your desired frame has been downloaded, so you have to force the movie to perform the ifFrameLoaded check repeatedly until the specified frame is loaded.
To watch your movie playback as it would over the Web, choose Control➪ Show Streaming. You’ll see the playhead in the timeline looping around your ifFrameLoaded action while it waits for the movie to download. The green bar in the timeline indicates how much of the movie has downloaded.
There are some general guidelines to keep in mind when you make a preloader. First, preloaders do not work inside Movie Clips. You cannot preload individual portions of a Movie Clip. If a Movie Clip instance is placed on a frame, the frame is not considered loaded until the entire instance has finished loading. Second, you don’t need to preload the entire movie when using preloaders. In our previous example, you could move the minimum_loadpoint keyframe to any point in the movie after frame 5. By using the streaming emulator in Test Movie Mode, you can determine approximately how much of your movie should be loaded before you allow it to play. Also, by using more than one preloader you can show the first part of a movie and then reenter a loading state before showing any subsequent parts.
Preloading with _framesLoaded and _totalFrames
In Flash 3, the only tool developers had to create preloaders was the If Frame is Loaded action. Using multiple preloaders, developers attempted to simulate a percentage-loaded feature that told the user how much of the movie had been downloaded. Although they demonstrated the ingenuity of the developers, these percentage-loaded indicators were mostly inaccurate. With the introduction of ActionScript in Flash 4, developers had a way to precisely determine the percentage of frames that have been downloaded to the user’s system. In this section, we convert the preloading mechanism of the preloader_1.fla movie to the _frames Loaded and _total Frames method.
When the playhead reaches frame 4, Flash executes the script. If, at that time, it finds that the number of frames downloaded is fewer than the number of total frames in the movie, it sends the playhead back to the preload_loop keyframe. Then it updates the percentageOutput variable to show, as a percentage, how many frames have loaded relative to the total number of frames in the movie. If, on the other hand, the number of frames loaded is not less than the total number of frames in the movie (in other words, if all the frames have loaded), then the playhead is moved to the begin_movie keyframe, and the movie proper starts playing.
An interesting variation on this advanced style of preloading is a graphical preload bar. A preload bar would simply be a small Movie Clip that contains a rectangle shape. Once placed on stage, the width of the bar would be set using the _xscale property to adjust the width percentage of the rectangle Movie Clip instance. The following steps show you how to do this.
Make sure you change the text block into a dynamic text field.
Because we want to the bar to grow from left to right, we need to make sure that the registration point is on the left edge of the rectangle.
Both the text-based and graphical preloaders are not accurate measurements of downloaded file size. They measure only the number of frames that have been downloaded. So, if the content of your movie is distributed evenly over the frames of the timeline, the frames-based percentage values will closely match the real filesize transfer percentage.
If, however, your heaviest content occurs only on sporadic frames (as our examples have demonstrated), then the frames-based percentage values may appear imprecise to the user. When such a movie is streamed, the progress bar will jump to discrete sizes regardless of connection speed or duration. Our next example demonstrates a new Flash 5 method for measuring the load progress of a Flash movie.
Using getBytesLoaded( ) and getBytesTotal( ) in Flash 5
By far the most accurate way to check the loading progress of a streaming Flash movie is to use the new Flash 5 methods getBytesLoaded() and getBytesTotal().
As their names indicate, you can now access the actual number of bytes that have downloaded to the browser or stand-alone player. With these new methods, we don’t need to try to disperse content evenly over frames on the Main Timeline—we can simply place our content where and when we want it.
We continue with the preloader_2.fla that we created in the last exercise. If you want to open a fresh file, use a copy of the preloader_2.fla file from the Flash 5 Bible.
In Step 1, we’ve changed loadedFrames to loadedBytes, and more importantly, we’ve made the value of loadedBytes equal the current number of bytes of the main movie file (_root) that have loaded into the Flash Player. Likewise, we’ve switched totalFrames to totalBytes, and made its value equal to the total number of bytes for the main movie file. Make sure you’ve also changed the if condition to indicate the new variable names, as well as the math expression for the percentageOutput variable.
Flash Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Adobe Flex 3 Interview Questions||Dreamweaver Interview Questions|
|3D Animation Interview Questions||Adobe Flash CS6 Interview Questions|
|Dreamweaver CS3 Interview Questions||Adobe Flex Interview Questions|
|Adobe Flex Actionscript Interview Questions||Gif Animation Interview Questions|
|Adobe Fireworks Interview Questions|
Understanding The Flash Framework
Exploring The Interface: Panels, Settings, And More
Using Tools For Navigation And Viewing
Working With Selections And The Pen Tool
Working With The Drawing And Painting Tools
Working With Text
Exploring The Timeline
Checking Out The Library: Symbols And Instances
Drawing In Flash
Animating In Flash
Using Bitmaps And Other Media With Flash
Designing Interfaces And Interface Elements
Understanding Sound For Flash
Importing And Editing Sounds In Flash
Optimizing Flash Sound For Export
Understanding Actions And Event Handlers
Navigating Flash Timelines
Controlling Movie Clips
Sharing And Loading Assets
Planning Code Structures
Creating Subroutines And Manipulating Data
Understanding Movie Clips As Complex Objects
Sending Data In And Out Of Flash
Understanding Html And Text Field Functions In Flash
What Is Generator?
Revving Up Generator
Working With Third-party, Server-side Applications
Working With Raster Graphics
Working With Vector Graphics
Working With Audio Applications
Working With 3d Graphics
Working With Quicktime
Working With Realplayer
Creating Full-motion Video With Flash
Creating Cartoon Animation With Flash
Planning Flash Production With Flowcharting Software
Working With Authoring Applications
Publishing Flash Movies
Integrating Flash Content With Html
Using Players, Projectors, And Screensaver Utilities
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.