1 / 15

MMP 220 Multimedia Programming

ActionScript: Loading External Content with MovieClipLoader Class, Listener Objects, Preloaders, HitTest, Loading Sound. MMP 220 Multimedia Programming. This material was prepared for students in MMP220 Multimedia Programming as as part of a curriculum redesign project funded by

Télécharger la présentation

MMP 220 Multimedia Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ActionScript: Loading External Content with MovieClipLoader Class, Listener Objects, Preloaders, HitTest, Loading Sound MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia Programming as as part of a curriculum redesign project funded by National Science Foundation grant #0511209 Co PI’s Christopher Stein and Jody Culkin BMCC CUNY http://teachingmultimedia.net

  2. Benefits of Dynamically Loading Content • Your want to break your project down into parts that will download rapidly, rather than have the user download one enormous file • Much of your content is dynamically generated • Some parts of the application need to be updated frequently • Your application has several different authors or teams who are developing some part of the content

  3. Loading swf files: • When you load swf content using the MovieClipLoader class, the content replaces the timeline content of the containing clip, which is why it is a good idea to create an empty movieclip to contain your content. The content retains the _x, _y, _alpha, _xscale and _yscale properties.

  4. Syntax for loading swf //first create an empty clip to hold content this.createEmptyMovieClip("circleSWFHolder_mc",getNextHighestDepth()); //create a MovieClipLoader object var swfLoader_mcl:MovieClipLoader = new MovieClipLoader(); //use loadClip() method of the MovieClipLoader object, parameter is //url where clip is stored swfLoader_mcl.loadClip("http://www.person13.com/asb/circles.swf", circleSWFHolder_mc);

  5. Loading Images • You can load image files (jpeg, png, gif) into you Flash movies using the MovieClipLoader object. • When you load an image into a clip, it replaces the timeline content of the clip. This means that the object can no longer be treated fully as a clip- the methods of the movieClip class will not work on an image file. • So if, for example, you want to load an image and make it draggable, you must load the image content into a clip that is within a clip.

  6. Syntax for nesting clip into clip to load image content this.createEmptyMovieClip("imageHolder_mc",this.getNextHighestDepth()); imageHolder_mc.createEmptyMovieClip("image_mc", imageHolder_mc.getNextHighestDepth()); var imageLoader:MovieClipLoader = new MovieClipLoader(); imageLoader.loadClip("batman.jpg", imageHolder_mc.image_mc);

  7. MovieClipLoader Class, and Listener Objects • MovieClipLoader objects work with listener objects, which monitor the progress of loading content. A listener object for a MovieClipLoader instance is just an object that has methods of the MovieClipLoader class defined.

  8. Methods Defined • onLoadStart() - invoked when content begins to load- passed a reference to MovieClip object into which content will be loaded. • onLoadProgress() – invoked continually while data is loaded. 3 parameters are passed- name of MovieClip into which data will be loaded, number of loaded bytes, number of total bytes. • onLoadInit() - invoked when data has loaded and is initialized. • onLoadComplete() – invoked when content has completely loaded. Parameter passed is reference to MovieClip object into which content was loaded.

  9. Example var myListener:Object = new Object(); myListener.onLoadStart = function(holderClip_mc:MovieClip):Void{ trace(holderClip_mc +” started loading”); }; myListener.onLoadProgress= function(holderClip_mc:MovieClip, nloaded:Number, nTotal:Number):Void{ trace(holderClip_mc + nloaded + “ of “ + nTotal + “ bytes”); }; myListener.onLoadInit=function(holderClip_mc:MovieClip):Void{ trace(holderClip_mc + “ initialized”); }; myListener.onLoadComplete = function(holderClip:MovieClip):Void{ trace(holderClip_mc + “ completed loading.”) This creates a listener object, and traces information about download progress of a clip into the output window.

  10. To use a MovieClipLoader listener: Create a movieClip object to load content into this.createEmptyMovieClip(“holder_mc”, this.getNextHighest Depth()); Next create a MovieClipLoader object var loader_mcl:MovieClipLoader= new MovieClipLoader(); Create a listener object var myListener:Object = new Object(); Use addListener() method to add the listener object ot the MovieClipLoader instance loader_mcl.addListener(myListener); Invoke loadClip() method from MovieClipLoader object

  11. Preloaders Preloaders use the methods of the MovieClipLoader Class to monitor progress of the download and convert the information into something the user can view, such as a bar whose length increases proportionally as the clip loads, or as numbers that identify the percentage of the clip that has loaded.

  12. Unloading Content You can unload content from a clip by either: • Loading new content into the clip • Using the unloadClip() method of the MovieClipLoader Class. This requires one parameter, a reference to the movieClip that was loaded with a MovieClipLoader.

  13. hitTest() • A method that checks for overlap- you can use to see if 2 clips have overlapped. • This example checks to see if circle_mc is overlapping square_mc and stores the result of the check in a Boolean variable overlap var overlap:Boolean= circle_mc.hitTest(square_mc);

  14. hitTest() example 2 • Another way to use hitTest() is to pass it 3 parameters, and X coordinate, a Y coordinate, and a Boolean value that indicates whether you want to test on the actual shape of the object, or the bounding box of the object. Example: var overlap:Boolean = circle_mc.hitTest(this._xmouse, this._ymouse, true); • This checks to see if the mouse is currently over the object circle_mc.

  15. Assignment • Read pages 277 – 285 in Chapter 14 of the ActionScript Bible.

More Related