




免费预览已结束,剩余6页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Flash AS3教程:组件的组合运用制作FLV播放器本例为Flash AS3实例教程,主要学习组件的组合运用制作FLV播放器,通过本教程将实现以下功能,按前进、后退按钮可选择播放,拖动滑块可调节音量,希望能给朋友们带来帮助组件的组合运用(FLV播放器)声明:本实例为Adobe的实例,非本人原创。实现的功能:按前进、后退按钮可选择播放,拖动滑块可调节音量。测试环境:Flash CS4、组织界面: 新建Flash文档文件,命名保存。 打开组件面板,点开User Interface组。把Label拖到场景中,命名为:postionLabel,拖ProgressBar到场景中,命名为:positionBar,拖Slider到场景中,命名为:volumeSlider,点开Video组。拖PlayButton到场景中,命名为:playButton,拖PauseButton到场景中,命名为:pauseButton,拖StopButton到场景中,命名为:stopButton,拖BackButton到场景中,命名为:backButton,拖ForwardButton到场景中,命名为:forwardButton。组织好位置如图1图2:、创建VideoJukebox.as文档文件,代码如下:(代码可直接拷贝)package import fl.controls.*; import fl.events.SliderEvent; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.events.NetStatusEvent; import flash.events.TimerEvent; import flash.media.SoundTransform; import flash.media.Video; import .NetConnection; import .NetStream; import .URLLoader; import .URLRequest; import flash.utils.Timer; public class VideoJukebox extends Sprite /* * The amount of time between calls to update the playhead timer, in * milliseconds. */ private const PLAYHEAD_UPDATE_INTERVAL_MS:uint = 10; /* * The path to the XML file containing the video playlist. */ private const PLAYLIST_XML_URL:String = playlist.xml; /* * The client object to use for the NetStream object. */ private var client:Object; /* * The index of the currently playing video. */ private var idx:uint = 0; /* * A copy of the current videos metadata object. */ private var meta:Object; private var nc:NetConnection; private var ns:NetStream; private var playlist:XML; private var t:Timer; private var uldr:URLLoader; private var vid:Video; private var videosXML:XMLList; /* * The SoundTransform object used to set the volume for the NetStream. */ private var volumeTransform:SoundTransform; /* * Constructor */ public function VideoJukebox() / Initialize the uldr variable which will be used to load the external / playlist XML file. uldr = new URLLoader(); uldr.addEventListener(Event.COMPLETE, xmlCompleteHandler); uldr.load(new URLRequest(PLAYLIST_XML_URL); /* * Once the XML file has loaded, parse the file contents into an XML object, * and create an XMList for the video nodes in the XML. */ private function xmlCompleteHandler(event:Event):void playlist = XML(event.target.data); videosXML = playlist.video; main(); /* * The main application. */ private function main():void volumeTransform = new SoundTransform(); / Create the client object for the NetStream, and set up a callback / handler for the onMetaData event. client = new Object(); client.onMetaData = metadataHandler; nc = new NetConnection(); nc.connect(null); / Initialize the NetSteam object, add a listener for the netStatus / event, and set the client for the NetStream. ns = new NetStream(nc); ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); ns.client = client; / Initialize the Video object, attach the NetStram, and add the Video / object to the display list. vid = new Video(); vid.x = 20; vid.y = 75; vid.attachNetStream(ns); addChild(vid); / Begin playback of the first video. playVideo(); / Initialize the Timer object and set the delay to / PLAYHEAD_UPDATE_INTERVAL_MS milliseconds. t = new Timer(PLAYHEAD_UPDATE_INTERVAL_MS); t.addEventListener(TimerEvent.TIMER, timerHandler); / Configure the positionBar ProgressBar instance and set the mode to / MANUAL. Progressbar values will be explicitly set using the / setProgress() method. positionBar.mode = ProgressBarMode.MANUAL; / Configure the volumeSlider Slider component instance. The maximum / value is set to 1 because the volume in the SoundTransform object / is set to a number between 0 and 1. The snapInterval and tickInterval / properties are set to 0.1 which allows users to set the volume to / 0, 0.1 - 0.9, 1.0 which allows users to increment or decrement the / volume by 10%. volumeSlider.value = volumeTransform.volume; volumeSlider.minimum = 0; volumeSlider.maximum = 1; volumeSlider.snapInterval = 0.1; volumeSlider.tickInterval = volumeSlider.snapInterval; / Setting the liveDragging property to true causes the Slider / instances change event to be dispatched whenever the slider is / moved, rather than when the user releases the slider thumb. volumeSlider.liveDragging = true; volumeSlider.addEventListener(SliderEvent.CHANGE, volumeChangeHandler); / Configure the various Button instances. Each Button instance uses / the same click handler. playButton.addEventListener(MouseEvent.CLICK, buttonClickHandler); pauseButton.addEventListener(MouseEvent.CLICK, buttonClickHandler); stopButton.addEventListener(MouseEvent.CLICK, buttonClickHandler); backButton.addEventListener(MouseEvent.CLICK, buttonClickHandler); forwardButton.addEventListener(MouseEvent.CLICK, buttonClickHandler); /* * Event listener for the volumeSlider instance. Called when the user * changes the value of the volume slider. */ private function volumeChangeHandler(event:SliderEvent):void / Set the volumeTransforms volume property to the current value of the / Slider and set the NetStream objects soundTransform property. volumeTransform.volume = event.value; ns.soundTransform = volumeTransform; /* * Event listener for the ns object. Called when the net streams status * changes. */ private function netStatusHandler(event:NetStatusEvent):void try switch (.code) case NetStream.Play.Start : / If the current code is Start, start the timer object. t.start(); break; case NetStream.Play.StreamNotFound : case NetStream.Play.Stop : / If the current code is Stop or StreamNotFound, stop / the timer object and play the next video in the playlist. t.stop(); playNextVideo(); break; catch (error:TypeError) / Ignore any errors. /* * Event listener for the ns objects client property. This method is called * when the net stream object receives metadata information for a video. */ private function metadataHandler(metadataObj:Object):void / Store the metadata information in the meta object. meta = metadataObj; / Resize the Video instance on the display list with the videos width / and height from the metadata object. vid.width = meta.width; vid.height = meta.height; / Reposition and resize the positionBar progress bar based on the / current videos dimensions. positionBar.move(vid.x, vid.y + vid.height); positionBar.width = vid.width; /* * Retrieve the current video from the playlist XML object. */ private function getVideo():String return videosXMLidx.url; /* * Play the currently selected video. */ private function playVideo():void var url:String = getVideo(); ns.play(url); /* * Decrease the current video index and begin playback of the video. */ private function playPreviousVideo():void if (idx 0) idx-; playVideo(); / Make sure the positionBar progress bar is visible. positionBar.visible = true; /* * Increase the current video index and begin playback of the video. */ private function playNextVideo():void if (idx (videosXML.length() - 1) / If this is not the last video in the playlist increase the / video index and play the next video. idx+; playVideo(); / Make sure the positionBar progress bar is visible. positionBar.visible = true; else / If this is the last video in the playlist increase the video / index, clear the contents of the Video object and hide the / positionBar progress bar. The video index is increased so that / when the video ends, clicking the backButton will play the / correct video. idx+; vid.clear(); positionBar.visible = false; /* * Click handler for each of the video playback buttons. */private function buttonClickHandler(event:MouseEvent):void / Use a switch statement to determine which button was clicked. switch (event.currentTarget) case playButton : / If the play button was clicked, resume the video playback. / If the video was already playing, this has no effect. ns.resume(); break; case pauseButton : / If the pause button was clicked, pause the video playback. / If the video was already playing, the video will be paused. / If the video was already paused, the video will be resumed. ns.togglePause(); break; case stopButton : / If the stop button was clicked, pause the video playback / and reset the playhead back to the beginning of the video. ns.pause(); ns.seek(0); break; case backButton : / If the back button was clicked,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高速驾校考试题目及答案
- 钢筋工理论考试题及答案
- 甘肃党史考试题型及答案
- 2025年的上海租房合同范本
- 2025建筑施工劳务合同
- 2025年中国石化用涂料项目投资计划书
- 电机与拖动考试题及答案
- 滴滴出行考试题及答案
- 单招乐理考试题及答案
- 2025年中国水性催干剂项目商业计划书
- 部编版小学-道德与法制2二年级上册-全册课件(新教材)
- 心理测验技能3课件带习题
- SLT824-2024 水利工程建设项目文件收集与归档规范
- 闽2023-G-01先张法预应力高强混凝土管桩DBJT13-95
- SJ-T 11798-2022 锂离子电池和电池组生产安全要求
- 法治及其本土资源
- 沪教版(上海)初中数学九年级第一学期-25.3(2)-解直角三角形-课件-课件PPT
- 新标准大学英语综合教程3课文翻译(1-10单元30篇)
- ABPA诊治进展(张家港中医院冯高华)
- 安全- 中国移动认证考试L1题库(附答案)
- 广告及宣传用品设计申请单
评论
0/150
提交评论