Flash CS3 Documentation |
|||
| Getting Started with Flash Lite 2.x > Tutorial: Creating a Flash Lite Application > Create the application > Create the video screen | |||
In this section, you'll add video to the application, as well as ActionScript code that lets the user control playback (play, pause, replay) with the right soft key.
In this tutorial, you'll bundle the device video file in your SWF file's library, although you can also load an external video file from the device's file system or a network address.
The Video Properties dialog box appears.
If you don't see the video file listed in the Open dialog box (or if you can see it but can't select it), select All Files (*.*) from the Files of Type pop-up menu (Windows), or All Files from the Enable pop-up menu (Macintosh). This action is sometimes necessary because the Flash authoring tool doesn't recognize most device video formats.
The Video Properties dialog box should appear as follows before you click OK.
A new video symbol appears in your document's Library panel that is associated with the device video file.
For more information about working with a device video in Flash Lite, see Using device video in Developing Flash Lite 2.x Applications.
// Stop timeline, register soft keys, and start video.
stop ();
fscommand2 ("SetSoftKeys", "Home", "Pause");
caféVideo.play ();
var playing:Boolean = true;
// Soft key event handler code:
Key.removeListener (myListener);
var myListener:Object = new Object ();
myListener.onKeyDown = function () {
var keyCode = Key.getCode ();
if (keyCode == ExtendedKey.SOFT1) {
gotoAndPlay ("home");
}
else if (keyCode == ExtendedKey.SOFT2) {
if (playing) {
// If video is playing, pause it,
// set status variable (playing) to false,
// and set right soft key label to 'Play'.
caféVideo.pause ();
playing = false;
rightSoftKeyLabel.text = "Play";
}
else {
// If video is paused, resume its playback,
// set status variable (playing) to true,
// and set right soft key label to 'Pause'.
caféVideo.resume ();
playing = true;
righttSoftKeyLabel.text = "Pause";
}
}
};
// Register listener object:
Key.addListener (myListener);
//
// Video status handler code.
//
caféVideo.onStatus = function (infoObject:Object) {
var code = infoObject.code;
if (code == "completed") {
// If video has finished playing, set playing=false,
// and set right soft key label to "Replay":
playing = false;
rightSoftKeyLabel.text = "Replay";
}
};
Try pausing the video by pressing the right soft key, and pressing the same key again to resume playback. When the video completes, you can press the right soft key again to play the video again.
Flash CS3