Tài liệu Flash: ActionScript Language Reference- P7 ppt

100 364 0
Tài liệu Flash: ActionScript Language Reference- P7 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MovieClipLoader class 601 Listener summary for the MovieClipLoader class Constructor for the MovieClipLoader class Availability Flash Player 7. Usage new MovieClipLoader() : MovieClipLoader Parameters None. Returns A reference to a MovieClipLoader object. Description Constructor; creates a MovieClipLoader object that you can use to implement a number of listeners to respond to events while a SWF or JPEG file is downloading. Example See MovieClipLoader.loadClip(). See also MovieClipLoader.addListener() Listener Description MovieClipLoader.onLoadComplete Invoked when a file loaded with MovieClipLoader.loadClip() has completely downloaded. MovieClipLoader.onLoadError Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load. MovieClipLoader.onLoadInit Invoked when the actions on the first frame of the loaded clip have been executed. MovieClipLoader.onLoadProgress Invoked every time the loading content is written to disk during the loading process. MovieClipLoader.onLoadStart Invoked when a call to MovieClipLoader.loadClip() has successfully begun to download a file. 602 Chapter 2: ActionScript Language Reference MovieClipLoader.addListener() Availability Flash Player 7. Usage my_mcl.addListener(listenerObject:Object) : Void Parameters listenerObject An object that listens for a callback notification from the MovieClipLoader event handlers. Returns Nothing. Description Method; registers an object to receive notification when a MovieClipLoader event handler is invoked. Example The following example loads an image into a movie clip called image_mc . The movie clip instance is rotated and centered on the Stage, and both the Stage and movie clip have a stroke drawn around their perimeters. this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { target_mc._x = Stage.width/2-target_mc._width/2; target_mc._y = Stage.height/2-target_mc._width/2; var w:Number = target_mc._width; var h:Number = target_mc._height; target_mc.lineStyle(4, 0x000000); target_mc.moveTo(0, 0); target_mc.lineTo(w, 0); target_mc.lineTo(w, h); target_mc.lineTo(0, h); target_mc.lineTo(0, 0); target_mc._rotation = 3; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); See also MovieClipLoader.onLoadComplete, MovieClipLoader.onLoadError, MovieClipLoader.onLoadInit, MovieClipLoader.onLoadProgress, MovieClipLoader.onLoadStart, MovieClipLoader.removeListener() MovieClipLoader.getProgress() 603 MovieClipLoader.getProgress() Availability Flash Player 7. Usage my_mcl.getProgress(target_mc:Object) : Object Parameters target_mc A SWF or JPEG file that is loaded using MovieClipLoader.loadClip(). Returns An object that has two integer properties: bytesLoaded and bytesTotal . Description Method; returns the number of bytes loaded and total number of bytes for a file that is being loaded using MovieClipLoader.loadClip(); for compressed movies, it reflects the number of compressed bytes. This method lets you explicitly request this information, instead of (or in addition to) writing a MovieClipLoader.onLoadProgress listener function. Example The following example loads an image into a draggable, dynamically created movie clip called image_mc . The number of bytes loaded and the total number of bytes for the loaded image display in a dynamically created text field called filesize_txt . this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { target_mc.onPress = function() { this.startDrag(); }; target_mc.onRelease = function() { this.stopDrag(); }; var mclProgress:Object = image_mcl.getProgress(target_mc); target_mc.createTextField("filesize_txt", target_mc.getNextHighestDepth(), 0, target_mc._height, target_mc._width, 22); target_mc.filesize_txt.text = mclProgress.bytesLoaded+" of "+mclProgress.bytesTotal+" bytes loaded"; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); See also MovieClipLoader.onLoadProgress 604 Chapter 2: ActionScript Language Reference MovieClipLoader.loadClip() Availability Flash Player 7. Usage my_mcl.loadClip(url:String, target:Object ) : Boolean Parameters url The absolute or relative URL of the SWF file or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///. Filenames cannot include disk drive specifications. target The target path of a movie clip, or an integer specifying the level in Flash Player into which the movie will be loaded. The target movie clip is replaced by the loaded SWF file or image. Returns A Boolean value. The return value is true if the URL request was sent successfully; otherwise the return value is false . Description Method; loads a SWF or JPEG file into a movie clip in Flash Player while the original movie is playing. Using this method lets you display several SWF files at once and switch between SWF files without loading another HTML document. Using this method instead of loadMovie() or MovieClip.loadMovie() has a number of advantages. The following handlers are implemented by the use on a listener object, which is registered with the MovieClipLoader class using MovieClipLoader.addListener(listenerObject) . • The MovieClipLoader.onLoadStart handler is invoked when loading begins. • The MovieClipLoader.onLoadError handler is invoked if the clip cannot be loaded. • The MovieClipLoader.onLoadProgress handler is invoked as the loading process progresses. • The MovieClipLoader.onLoadInit handler is invoked after the actions in the first frame of the clip have executed, so you can begin manipulating the loaded clip. • The MovieClipLoader.onLoadComplete handler is invoked when a file has completed downloading. A SWF file or image loaded into a movie clip inherits the position, rotation, and scale properties of the movie clip. You can use the target path of the movie clip to target the loaded movie. You can use the loadClip() method to load one or more files into a single movie clip or level; MovieClipLoader listener objects are passed the loading target movie clip instance as a parameter. Alternately, you can create a different MovieClipLoader object for each file you load. Use MovieClipLoader.unloadClip() to remove movies or images loaded with this method or to cancel a load operation that is in progress. MovieClipLoader.loadClip() 605 MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress do not report the actual bytesLoaded and bytesTotal values in the Authoring player when the files are local. When you use the Bandwidth Profiler feature in the authoring environment, MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress report the download at the actual download rate, not at the reduced bandwidth rate that the Bandwidth Profiler provides. Example The following example illustrates the use of many of the MovieClipLoader class methods and listeners: // first set of listeners var my_mcl:MovieClipLoader = new MovieClipLoader(); var myListener:Object = new Object(); myListener.onLoadStart = function(target_mc:MovieClip) { trace("*********First my_mcl instance*********"); trace("Your load has begun on movie clip = "+target_mc); var loadProgress:Object = my_mcl.getProgress(target_mc); trace(loadProgress.bytesLoaded+" = bytes loaded at start"); trace(loadProgress.bytesTotal+" = bytes total at start"); }; myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) { trace("*********First my_mcl instance Progress*********"); trace("onLoadProgress() called back on movie clip "+target_mc); trace(loadedBytes+" = bytes loaded at progress callback"); trace(totalBytes+" = bytes total at progress callback"); }; myListener.onLoadComplete = function(target_mc:MovieClip) { trace("*********First my_mcl instance*********"); trace("Your load is done on movie clip = "+target_mc); var loadProgress:Object = my_mcl.getProgress(target_mc); trace(loadProgress.bytesLoaded+" = bytes loaded at end"); trace(loadProgress.bytesTotal+" = bytes total at end"); }; myListener.onLoadInit = function(target_mc:MovieClip) { trace("*********First my_mcl instance*********"); trace("Movie clip = "+target_mc+" is now initialized"); // you can now do any setup required, for example: target_mc._width = 100; target_mc._height = 100; }; myListener.onLoadError = function(target_mc:MovieClip, errorCode:String) { trace("*********First my_mcl instance*********"); trace("ERROR CODE = "+errorCode); trace("Your load failed on movie clip = "+target_mc+"\n"); }; my_mcl.addListener(myListener); // Now load the files into their targets. // loads into movie clips this.createEmptyMovieClip("clip1_mc", this.getNextHighestDepth()); clip1_mc._x = 400; this.createEmptyMovieClip("clip2_mc", this.getNextHighestDepth()); 606 Chapter 2: ActionScript Language Reference my_mcl.loadClip("http://www.macromedia.com/software/drk/images/box_drk5.jpg", clip1_mc); my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/ ben_forta.jpg", clip2_mc); clip2_mc._x = 200; // loads into _level1 my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/ mike_chambers.jpg", 1); // // Second set of listeners var another_mcl:MovieClipLoader = new MovieClipLoader(); var myListener2:Object = new Object(); myListener2.onLoadStart = function(target_mc:MovieClip) { trace("*********Second my_mcl instance*********"); trace("Your load has begun on movie = "+target_mc); var loadProgress:Object = my_mcl.getProgress(target_mc); trace(loadProgress.bytesLoaded+" = bytes loaded at start"); trace(loadProgress.bytesTotal+" = bytes total at start"); }; myListener2.onLoadComplete = function(target_mc:MovieClip) { trace("*********Second my_mcl instance*********"); trace("Your load is done on movie clip = "+target_mc); var loadProgress:Object = my_mcl.getProgress(target_mc); trace(loadProgress.bytesLoaded+" = bytes loaded at end"); trace(loadProgress.bytesTotal+" = bytes total at end"); }; myListener2.onLoadError = function(target_mc:MovieClip, errorCode:String) { trace("*********Second my_mcl instance*********"); trace("ERROR CODE = "+errorCode); trace("Your load failed on movie clip = "+target_mc+"\n"); }; another_mcl.addListener(myListener2); /* Now load the files into their targets (using the second instance of MovieClipLoader) */ another_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/ flex_logo.jpg", this.createEmptyMovieClip("clip4_mc", this.getNextHighestDepth())); clip4_mc._y = 200; // Issue the following statements after the download is complete, // and after my_mcl.onLoadInit has been called. // my_mcl.removeListener(myListener); // my_mcl.removeListener(myListener2); See also MovieClipLoader.unloadClip() MovieClipLoader.onLoadComplete 607 MovieClipLoader.onLoadComplete Availability Flash Player 7. Usage listenerObject.onLoadComplete = function([target_mc:Object]) { // your statements here } Parameters listenerObject A listener object that was added using MovieClipLoader.addListener(). target_mc A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional. Returns Nothing. Description Listener; invoked when a file loaded with MovieClipLoader.loadClip() has completely downloaded. The value for target_mc identifies the movie clip for which this call is being made. This is useful if multiple files are being loaded with the same set of listeners. This parameter is passed by Flash to your code, but you do not have to implement all of the parameters in the listener function. When you use the onLoadComplete and onLoadInit events with the MovieClipLoader class, it’s important to understand how this differs from the way they work with your SWF file. The onLoadComplete event is called after the SWF or JPEG file has loaded, but before the application has been initialized. At this point it is impossible to access the loaded movie clip’s methods and properties, and because of this you cannot call a function, move to a specific frame, and so on. In most situations, it’s better to use the onLoadInit event instead, which is called after the content has loaded and is fully initialized. Example The following example loads an image into a movie clip instance called image_mc . The onLoadInit and onLoadComplete events are used to determine how long it takes to load the image. The information displays in a dynamically created text field called timer_txt . this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadStart = function(target_mc:MovieClip) { target_mc.startTimer = getTimer(); }; mclListener.onLoadComplete = function(target_mc:MovieClip) { target_mc.completeTimer = getTimer(); }; mclListener.onLoadInit = function(target_mc:MovieClip) { var timerMS:Number = target_mc.completeTimer-target_mc.startTimer; 608 Chapter 2: ActionScript Language Reference target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(), 0, target_mc._height, target_mc._width, 22); target_mc.timer_txt.text = "loaded in "+timerMS+" ms."; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); See also MovieClipLoader.addListener(), MovieClipLoader.onLoadStart, MovieClipLoader.onLoadError MovieClipLoader.onLoadError 609 MovieClipLoader.onLoadError Availability Flash Player 7. Usage listenerObject.onLoadError = function(target_mc:Object, errorCode:String) { // your statements here } Parameters listenerObject A listener object that was added using MovieClipLoader.addListener(). target_mc A movie clip loaded by a MovieClipLoader.loadClip() method. errorCode A string that explains the reason for the failure. Returns One of two strings: "URLNotFound" or "LoadNeverCompleted" . Description Listener; invoked when a file loaded with MovieClipLoader.loadClip() has failed to load. The string "URLNotFound" is returned if neither the MovieClipLoader.onLoadStart or MovieClipLoader.onLoadComplete listener has been called. For example, if a server is down or the file is not found, these listeners are not called. The string "LoadNeverCompleted" is returned if MovieClipLoader.onLoadStart was called but MovieClipLoader.onLoadComplete was not called. For example, if MovieClipLoader.onLoadStart is called but the download is interrupted due to server overload, server crash, and so on, MovieClipLoader.onLoadComplete will not be called. The value for target_mc identifies the movie clip this call is being made for. This is useful if you are loading multiple files with the same set of listeners. This optional parameter is passed to your ActionScript. Example The following example displays information in the Output panel when an image fails to load. This occurs when you test the following ActionScript, because the image does not exist in the specified location. this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var mclListener:Object = new Object(); mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String) { trace("ERROR!"); switch (errorCode) { case 'URLNotFound' : trace("\t Unable to connect to URL: "+target_mc._url); break; case 'LoadNeverCompleted' : trace("\t Unable to complete download: "+target_mc); break; 610 Chapter 2: ActionScript Language Reference } }; mclListener.onLoadInit = function(target_mc:MovieClip) { trace("success"); trace(image_mcl.getProgress(target_mc).bytesTotal+" bytes loaded"); }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.fakedomain.com/images/bad_hair_day.jpg", image_mc); [...]... MovieClipLoader.unloadClip() 619 CHAPTER 2 ActionScript Language Reference NaN Availability Flash Player 5 Usage NaN Description Variable; a predefined variable with the IEEE-754 value for NaN (not a number) To determine if a number is NaN, use isNaN() See also isNaN(), Number.NaN 620 Chapter 2: ActionScript Language Reference -Infinity CHAPTER 2 ActionScript Language Reference Availability Flash Player... connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video2.flv"); See also NetStream class 624 Chapter 2: ActionScript Language Reference CHAPTER 2 ActionScript Language Reference NetStream class Availability Flash Player 7 Note: This class is also supported in Flash Player 6 when used with Flash Communication Server For more information,... management, and independent video and Flash frame rates For more information on video playback, see “Playing back external FLV files dynamically” in Using ActionScript in Flash Example See the example for NetConnection.connect() 622 Chapter 2: ActionScript Language Reference See also NetStream class, Video.attachVideo() NetConnection class 623 NetConnection.connect() Availability Flash Player 7 Note: This... name my_video.Then add the following ActionScript to your FLA or AS file: var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); See also NetConnection class, NetStream class, Video.attachVideo() 626 Chapter 2: ActionScript Language Reference NetStream.bufferLength... image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); MovieClipLoader.onLoadInit 611 See also MovieClipLoader.onLoadStart 612 Chapter 2: ActionScript Language Reference MovieClipLoader.onLoadProgress Availability Flash Player 7 Usage listenerObject.onLoadProgress = function([target_mc:Object [, loadedBytes:Number [, totalBytes:Number ] ] ] )... Player 5 Usage -Infinity Description Constant; specifies the IEEE-754 value representing negative infinity The value of this constant is the same as Number.NEGATIVE_INFINITY -Infinity 621 CHAPTER 2 ActionScript Language Reference NetConnection class Availability Flash Player 7 Note: This class is also supported in Flash Player 6 when used with Flash Communication Server For more information, see the Flash... new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("[place a valid URL pointing to a JPEG file here]", image_mc); See also MovieClipLoader.getProgress() 614 Chapter 2: ActionScript Language Reference MovieClipLoader.onLoadStart Availability Flash Player 7 Usage listenerObject.onLoadStart = function([target_mc:Object]) { // your statements here } Parameters listenerObject target_mc... image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); MovieClipLoader.onLoadStart 615 See also MovieClipLoader.onLoadError, MovieClipLoader.onLoadInit, MovieClipLoader.onLoadComplete 616 Chapter 2: ActionScript Language Reference MovieClipLoader.removeListener() Availability Flash Player 7 Usage my_mcl.removeListener(listenerObject:Object) : Void Parameters listenerObject A listener object that was added... trace("Stopping "); MovieClipLoader.removeListener() 617 start_button.enabled = true; stop_button.enabled = false; // image_mcl.removeListener(mclListener); }; stop_button.enabled = false; 618 Chapter 2: ActionScript Language Reference MovieClipLoader.unloadClip() Availability Flash Player 7 Usage my_mcl.unloadClip(target:Object) Parameters target The string or integer passed to the corresponding call to my_mcl.loadClip()... "Length: "+my_ns.bufferLength+"\t"+"Time: "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%"; output_str += ""; buffer_txt.htmlText = output_str; } See also NetStream.time 628 Chapter 2: ActionScript Language Reference NetStream.bytesLoaded Availability Flash Player 7 Usage my_ns.bytesLoaded:Number Description Read-only property; the number of bytes of data that have been loaded into the player . MovieClipLoader.loadClip() has successfully begun to download a file. 602 Chapter 2: ActionScript Language Reference MovieClipLoader.addListener() Availability Flash Player. 112x112/box_studio_112x112.jpg", image_mc); See also MovieClipLoader.onLoadProgress 604 Chapter 2: ActionScript Language Reference MovieClipLoader.loadClip() Availability Flash Player

Ngày đăng: 14/12/2013, 14:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan