Loading device-specific sound and image formats


 
Personalized wallpapers and screensavers for mobile phones

In Flash Lite 2.0, you can load any image or sound file that’s in a format supported by the device. To load external images, you use the loadMovie() global function, or the MovieClip.loadMovie() method. For example, if the device supports the PNG file format, then you could use the following code to load a PNG file from a web server into the movie clip instance image_mc:

image_mc.loadMovie("http://www.yoursite.com/images/yourimage.png");

To load external sounds, you use the Sound.loadSound() method. In Flash Lite 2.0, you can use this method to load any sound format that the mobile phones supports (for example, MIDI or SMAF). External device sounds must fully load into memory before they can play. As in Flash Lite 1.x, in Flash Lite 2.0 you can also play device sound that’s bundled in the SWF file.

Loading external images

In Flash Lite 2.0, as in Flash Lite 1.1, you can use the loadMovie() function (or, equivalently, the loadMovie() method of the MovieClip object) to load external SWF files into your application. dditionally, in Flash Lite 2.0, you can use the loadMovie() function to load any arbitrary image format that the device supports.

For example, assuming that the target device can decode PNG files, the following code loads and displays an external PNG file that resides on the web server:
loadMovie("http://www.macromedia.com/image.png", "image_target");

To determine what image formats the target device supports, you can use the System.capabilities.imageMIMETypes property, which contains an array of supported image MIME types. The index of each element in the array is equal to each supported MIME type.
For example, the following ActionScript determines whether a device supports PNG images before the device attempts to load an external PNG file:
if (System.capabilities.imageMIMETypes["image/png"]) {
loadMovie("images/image.png", "mc_myPngImage");
}
Flash Lite limits to five the number of loadMovie() operations that an application can perform in a given frame, and 10 total operations at any one time. For example, suppose your application ontains code on frame 1 to load six external JPEG images, as shown below:
image1.loadMovie("image1.jpg");
image2.loadMovie("image2.jpg");
image3.loadMovie("image3.jpg");
image4.loadMovie("image4.jpg");
image5.loadMovie("image5.jpg");
image6.loadMovie("image6.jpg"); // Won’t load

In this case, only the first five images (image1.jpg through image5.jpg) will load; the last image (image6.jpg) will not load because the five connection limit is reached. One solution is to split the loadMovie() calls over multiple frames so that each frame contains a maximum of five loadMovie() calls.

Playing external device sounds

In addition to playing device sounds that are bundled in the published SWF file (see “Using bundled device sound” on page 48), you can also load and play external sound files. To play external device sounds you use the loadSound() method of the Sound object. As with bundled device sound, the Flash Lite player passes the externally loaded audio to the device to decode and play.

The following information about playing external device sounds in Flash Lite 2.0 is important to remember:

  • Unlike in the desktop version of Flash Player, externally loaded sounds in Flash Lite 2.0
    are always treated as event sounds. This means that external device sounds do not
    stream—that is, play as they are being downloaded. The sound data must download fully
    before you can play the sound. For the same reason, you must call the Sound object’s
    start() method to play the sound once it is fully loaded (see the following code
    example).
  • The Flash Lite 2.0 implementation of the loadSound() method does not support that
    method’s second parameter (isStreaming). Flash Lite ignores this parameter if it is
    present.
  • Flash Lite 2.0 does not play externally loaded MP3 files natively. If your application loads
    an external MP3 file, Flash Lite passes the sound data to the device to decode and play, as
    it does with any externally loaded sound file.

The following code shows how to load and play an external sound file:
// Create the sound object.
var mySound:Sound = new Sound();
// Define onLoad handler for sound,
// which starts the sound once it has fully loaded.
mySound.onLoad = function(success){
if(success == true) {
mySound.start();
}
}
// Load the sound.
mySound.loadSound("http://www.macromedia.com/audio.midi");

128x160 wallpapers

More info here http://livedocs.macromedia.com

Back to Flash Lite home