1 / 32

Multimedia Coding

Multimedia Coding. Objectives of this topic:. You can …. import movies, sound and flash video using AS3 code. control the playback of those items. Overview. Loading External Images and SWFs Communicating with Loaded Movies Loading Sound Starting and Stopping Sound

baird
Télécharger la présentation

Multimedia Coding

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. Multimedia Coding

  2. Objectives of this topic: You can … import movies, sound and flash video using AS3 code control the playback of those items

  3. Overview • Loading External Images and SWFs • Communicating with Loaded Movies • Loading Sound • Starting and Stopping Sound • Managing the Volume of Sound • Loading Video • Controlling Video Playback

  4. Loading External Images and SWFs • Load a variety of images and external swf files into a Flash movie using AS3 • The files are external which are not on the library panel • URLRequest class is used to get the location of the external image file var imageRequest:URLRequest = new URLRequest("snowboard.jpg");

  5. Followed by loading instruction to create an image loader – Loader class var imageLoader:Loader = new Loader(); imageLoader.load(imageRequest); addChild(imageLoader); • load() is method instructing the Loader to load the imageRequest file, ‘snowboard.jpg’ (Loading_Images)

  6. Type of image files that can be loaded in Flash movie – jpeg, png, and gif files • GIF files – best suited for graphics and logos, rather than photographs or more complicated images, because of the limited color palette. It uses 256 colors in the 24-bit RGB

  7. PNG files – used mainly for less color intensive graphics. Do not support animation as GIFs, but support more transparency and produce smaller file sizes than GIFs • JPEG files – smaller file sizes for photograph image. The most popular choice for photographs that are destined for the Web.

  8. External SWF file  load a SWF into another SWF file when intend to use the movie throughout the site. • SWF files are type of reusable asset that can be used in different project or replicated throughout a single project. (Loading_SWFMovie)

  9. Communicating with Loaded Movies • Modify objects in an external SWF file that has been loaded into another Flash movie • The modification can be done when only the external SWF file is completed loading.

  10. The following is the code that will trigger the onComplete event when SWF file is finished loading imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

  11. contentLoaderInfo- property of the Loader class that contains all the information about the target file (the external file that is being loaded) • To communicate with the loaded SWF file, export the class definition for that object at run time.

  12. Write the AS3 code to activate the external SWF file. Flash: Communicating, movie function onComplete(event:Event):void { event.target.content.boarder_mc.y -= 100; }

  13. event.target  the object being targeted by the event listener which is called contentLoaderInfo. • content  property referring to the actual object in the external movie • boarder_mc instance name of the movie clip residing in the external movie

  14. Loading Sounds • Using the same code, URLRequest class to points to the sound file. (Sound) var soundReq:URLRequest = new URLRequest("free_fade.mp3"); var sound:Sound = new Sound(); sound.load(soundReq);

  15. Three types of sound files in Flash CS3, and another six more files if QuickTime 4 is installed on users PC • Capable to import 8-bit or 16-bit sounds

  16. sound.addEventListener(Event.COMPLETE, onComplete); function onComplete(event:Event):void { sound.play(); } Flash: Sound_Complete

  17. Control the Sound • Use SoundChannel class to control the sound playback var soundControl:SoundChannel = new SoundChannel(); • Create new instance of the SoundChannel class named soundControl (Starting_Stopping)

  18. addEventListener is used to add interactivity to the external movie through the button play_btn.addEventListener(MouseEvent.CLICK, playSound); stop_btn.addEventListener(MouseEvent.CLICK, stopSound);

  19. Activate the playSound and stopSound event handler function playSound(event:MouseEvent):void { soundControl = sound.play(); } function stopSound(event:MouseEvent):void { soundControl.stop(); }

  20. Pausing the sound • Pause and resume the sound – the sound starts to play from wherever the user stopped the track. • Flash: Pause_Resume

  21. Sound class in Flash

  22. Managing the Volume of Sound • Use SoundTransform class to deal the volume of a sound var volumeControl:SoundTransform = new SoundTransform(); • Create new instance of the SoundTransform class

  23. Volume in sound property has a possible value between 0 – 1. volumeControl.volume += .5; soundControl.soundTransform = volumeControl; • ‘+= .1’ means increase the current volume by 50% every time the button is clicked (Volume_Control)

  24. Loading Video • Loading video with NetConnection object to stream a video from local drive or server varvideoConnection:NetConnection = new NetConnection(); • Specify the address source. ‘null’  same folder videoConnection.connect(null);

  25. Use NetStream object to connects to the hard drive using NetConnection path and streams the video passsed through in the parentheses varvideoStream:NetStream = new NetStream(videoConnection); videoStream.play("short_jump.flv");

  26. Attach the stream of the video and add it to the movie’s display list varvideo:Video = new Video(); video.attachNetStream(videoStream); addChild(video);

  27. var videoConnection:NetConnection = new NetConnection(); videoConnection.connect(null); var videoStream:NetStream = new NetStream(videoConnection); videoStream.play("short_jump.flv"); var video:Video = new Video(); video.attachNetStream(videoStream); addChild(video); Flash: Loading_Video

  28. Controlling Video Playback • Control the playback of loaded FLV files and handle the error messages during playback • Video playback do not use addEventListener method to listen for or process • It is applied the listener to the object that the client property of a NetStream instance references

  29. var metaListener:Object = new Object(); metaListener.onMetaData = onMetaData; • metaListener is an instance of the Object class which accepts all the methods and properties of any object descended from it • Second statement associates the new onMetaData() method (or event listener) with the generic object metaListener

  30. videoStream.client = metaListener; • videoStream.client is one of the only objects that can be applied the event listener to in the external file. • By associating it with the generic object, than we can listen for onMedaData Flash: Video_Playback

  31. function onMetaData(data:Object):void { play_btn.addEventListener(MouseEvent.CLICK, playMovie); stop_btn.addEventListener(MouseEvent.CLICK, stopMovie); } • Put the event listener in the function to make sure the external data (video) is fully loaded (Video_Control)

  32. function playMovie(event:MouseEvent):void { videoStream.play("short_jump.flv"); } function stopMovie(event:MouseEvent):void { videoStream.pause(); }

More Related