672
Working with External Data
7.
Add the following ActionScript to Frame 1 of the main Timeline:
import flash.external.ExternalInterface;
/* Register playVideo() and pauseResume() so that it is possible
to call them from JavaScript in the container HTML page. */
ExternalInterface.addCallback("playVideo", null, playVideo);
ExternalInterface.addCallback("pauseResume", null, pauseResume);
/* The video requires a NetConnection and NetStream object. */
var server_nc:NetConnection = new NetConnection();
server_nc.connect(null);
var video_ns:NetStream = new NetStream(server_nc);
/* Attach the NetStream object to the Video object on Stage so
that the NetStream data is displayed in the Video object. */
selected_video.attachVideo(video_ns);
/* The onStatus() method is called automatically when the status of
the NetStream object is updated (the video starts playing, for example).
When that occurs, send the value of the code property to the HTML page by
calling the JavaScript updateStatus() function via ExternalInterface. */
video_ns.onStatus = function(obj:Object):Void {
ExternalInterface.call("updateStatus", " " + obj.code);
};
function playVideo(url:String):Void {
video_ns.play(url);
}
function pauseResume():Void {
video_ns.pause();
}
The first part of this ActionScript code defines two ExternalInterface callback functions,
playVideo()
and
pauseResume()
. These functions are called from the JavaScript in the
next procedure. The second part of the code creates a new NetConnection and NetStream
object, which you use with the video instance to dynamically play back FLV files.
The code in the next procedure defines an
onStatus
event handler for the
video_ns
NetStream object. Whenever the NetStream object changes its status, Flash uses the
ExternalInterface.call()
method to trigger the custom JavaScript function,
updateStatus()
. The final two functions,
playVideo()
and
pauseResume()
, control
the playback of the video instance on the Stage. Both of these functions are called from
JavaScript written in the following procedure.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...