.
Images, bitmaps, videos, and sounds is a
mouthful and a far wider range of topics than could be adequately covered
in a single chapter, so this one concentrates on answering the most common
questions. As Flash becomes the primary method of delivering video over
the Internet and the use of the Flex Framework in creating photo and MP3
applications increases, understanding how to work with all of these
elements becomes more and more important. of data in the Flash Player: the BitmapData classes and
the ByteArray classes. These classes
enable you not only to manipulate the bitmap data of the images that you
load into the Flash Player, but they also let you create new bitmaps and
stream the data out.
Image
VideoDisplay
flash.media
Video
Sound
SoundTransform
Camera
Microphone
Loader
NetConnection
NetStream
flash.net
BitmapData
ByteArray.
You need to display an image in a Flex component.
Use either an Embed
statement to compile the image into the SWF file or load the
image at runtime.
Embed
Flex supports importing GIF, JPEG, PNG, and SWF files at runtime or at
compile time, and SVG files at compile time through embedding. The
method you choose depends on the file types of your images and your
application parameters. Any embedded images are already part of the
SWF file and so don't require any time to load. The trade-off is the
size that they add to your application, which slows the application
initialization process. Extensive use of embedded images also requires
you to recompile your applications whenever your image files
change.
Alternatively, you can load the resource at runtime by either
setting the source property of an
image to a URL or by using URLRequest objects and making the result of the load operation a BitmapAsset object. You can load a resource from the local file system in
which the SWF file runs, or you can access a remote resource,
typically through an HTTP request over a network. These images are
independent of your application; you can change them without needing
to recompile as long as the names of the modified images remain the
same.
source
URLRequest
BitmapAsset
Any SWF file can access only one type of external resource,
either local or over a network; it cannot access both types. You
determine the type of access allowed by the SWF file by using the
use-network flag when you compile
your application. When the use-network flag is set to false, you can access resources in the local
file system, but not over the network. The default value is true,
which allows you to access resources over the network, but not in the
local file system.
use-network
To embed an image file, use the Embed metadata property:
[Embed(source="../assets/flag.png")]
private var flag:Class;
Now this Class object can be
set as the source for an image:
Class
var asset:BitmapAsset = new flag() as BitmapAsset;
img3rd.source = asset;
Alternatively, you can set the property of the source to a local
or external file system:
<mx:Image
The full example follows:
<mx:VBox xmlns:
<mx:Script>
<![CDATA[
import mx.core.BitmapAsset;
[Embed(source="../assets/flag.png")]
private var flag:Class;
private function imgMod():void
{
var asset:BitmapAsset = new flag() as BitmapAsset;
img3rd.source = asset;
}
]]>
</mx:Script>
<mx:Image
<mx:Image
<mx:Image
</mx:VBox>
You need to display an FLV file in your application.
Use the VideoDisplay
class in your application and use Button instances to play and pause the
application if desired.
Button
The VideoDisplay class wraps
a flash.media.Video object and
simplifies adding video to that object considerably. The source attribute of the VideoDisplay is set to the URL of an FLV
file, and the autoplay
parameter is set to true so that when the NetStream has been properly instantiated and
the video information begins streaming to the player, the video will
begin playing:
flash.media.Video
autoplay
<mx:VideoDisplay
In the following example, buttons are set up to play, pause, and
stop the video by using the methods defined by the VideoDisplay class:
<mx:VBox xmlns:
<mx:VideoDisplay
<mx:HBox>
<mx:Button
<mx:Button
<mx:Button
</mx:HBox>
</mx:VBox>
You want to allow a user to play a series of MP3 files.
Use the Sound and SoundChannel classes and load new files by using progressive download when
the user selects a new MP3 file. 2015, O’Reilly Media, Inc.
(707) 827-7019
(800) 889-8969
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.