User Guide
114 Chapter 3: Using Best Practices
To dynamically load video using ActionScript:
1.
Add a video object to the Stage by selecting New Video from the Library panel’s options menu.
2.
Drag the video object on to the Stage, and resize the instance using the Property inspector to
the same dimensions as your FLV file.
3.
Enter an instance name of video1_video in the Property inspector.
4.
Select Frame 1 of the Timeline, and enter the following ActionScript into the Actions panel:
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
stream_ns.setBufferTime(3);
video1_video.attachVideo(stream_ns);
stream_ns.play("video1.flv");
5.
Rename video1.flv in the ActionScript to the name of the FLV file that you want to load.
6.
Save the FLA document in the same directory as your FLV file.
Performance and Flash Player
SWF file performance is important, and you can improve performance in many ways: from how
you write ActionScript, to how you build animations. This section provides guidelines and
practices that help improve the performance of your SWF file at runtime.
For more information, see the following topics:
• “Optimizing graphics and animation” on page 114
• “Working with components in Flash Player” on page 115
• “Preloading components and classes” on page 117
• “Working with text” on page 118
• “Optimizing ActionScript in Flash Player” on page 120
Optimizing graphics and animation
The first step in creating optimized and streamlined animations or graphics is to outline and plan
your project before its creation. Make a target for the file size and length of the animation that
you want to create, and test throughout the development process to ensure that you are on track.
If you are creating advertisements, for example, length and file size are extremely important.
Avoid using gradients, because they require many colors and calculations to be processed, which is
more difficult for a computer processor to render. For the same reason, keep the amount of alpha
or transparency you use in a SWF file to a minimum. Animating objects that include
transparency is processor-intensive and should be kept to a minimum. Animating transparent
graphics over bitmaps is a particularly processor-intensive kind of animation, and must be kept to
a minimum or avoided completely.
Note: The best bitmap format to import into Flash is PNG, which is the native file format of
Macromedia Fireworks. PNG files have RGB and alpha information for each pixel. If you import a
Fireworks PNG file into Flash, you retain some ability to edit the graphic objects in the FLA file.