标签:opd simple sim == || .com inf bounds ace
package com{ import flash.display.MovieClip; import flash.net.NetConnection; import flash.net.NetStream; import flash.events.AsyncErrorEvent; import flash.events.MouseEvent; import flash.media.Video; import flash.display.SimpleButton; import flash.events.Event; import flash.display.Loader; import flash.net.URLLoader; import flash.net.URLRequest; import flash.utils.Timer; import flash.events.TimerEvent; import flash.system.fscommand; import flash.media.SoundMixer; import flash.media.SoundTransform; import flash.display.Stage; import flash.geom.Rectangle; public class JYSLoader extends MovieClip { public static var nc:NetConnection; public static var ns:NetStream; public static var vid:Video; public static var emptyMc:MovieClip; public static var vidTotalTime:Number; public static var vidNowTime:Number; public static var obj:Object =new Object (); public static var videoPath:String; public static var vidProgressNum:Number; public static var soundTF:SoundTransform; public static var loader:Loader; public static var urlR:URLRequest; public static var backBtn:SimpleButton; public static var timer:Timer=new Timer(25); public static var thisMc:MovieClip; public static var stageMc:Stage; //视频==================================================================================================== public function JYSLoader(_thisMc:MovieClip ,_stageMc:Stage) { thisMc=_thisMc; stageMc=_stageMc; } public function vidFun() { nc= new NetConnection(); nc.connect(null); ns=new NetStream(nc); ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); ns.close(); vid=new Video(1920,1080); function asyncErrorHandler(event:AsyncErrorEvent ):void { // 忽略错误 } //vid.x=167.25; //vid.y=92.45; obj.onMetaData=onMetaData; ns.client=obj; function onMetaData(data:Object):void { vidTotalTime=data.duration; } vid.attachNetStream(ns); ns.pause(); vid.smoothing=true; } //加载==================================================================================================== public static function addMP4(str:String,_emptyMc:MovieClip,num:Number ) { emptyMc=_emptyMc; var string=stageMc.loaderInfo.url; var str1:int=string.lastIndexOf("/"); var str2:String=string.slice(0,str1+1); ns.play(str2+"vid/"+str+".mp4"); emptyMc.addChildAt(vid,num); /*if (timer.hasEventListener(TimerEvent.TIMER)==false) { timer.addEventListener(TimerEvent.TIMER,timerFun); timer.start(); }*/ } public static function timerFun(e:TimerEvent) { vidNowTime=ns.time; dragMc.x=int(lineMc.width*vidNowTime/vidTotalTime)+lineMc.x; var i:int=vidNowTime*lineMc.totalFrames/vidTotalTime; lineMc.gotoAndStop(i); if (vidTotalTime-vidNowTime<0.05||emptyMc.numChildren==0) { timer.removeEventListener(TimerEvent.TIMER,timerFun); ns.pause(); } } //卸载==================================================================================================== public static function removeMP4() { if (ns.time!=0) { ns.close(); emptyMc.removeChild(vid); timer.removeEventListener(TimerEvent.TIMER,timerFun); } } //加载swf====================================================================================================== public static function addSwf(swfStr:String,_emptyMc:MovieClip,num:Number ) { emptyMc=_emptyMc; removeMP4(); if (emptyMc.numChildren!=0) { loader.unloadAndStop(); while (emptyMc.numChildren>0) { emptyMc.removeChildAt(0); } } if (emptyMc.numChildren==0) { var string=stageMc.loaderInfo.url; var str1:int=string.lastIndexOf("/"); var str2:String=string.slice(0,str1+1); loader= new Loader(); urlR = new URLRequest(str2+swfStr+".swf"); loader.load(urlR); emptyMc.addChildAt(loader,num); //var loaderContent=loader.content; //trace(loaderContent.totalFrames) //loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoader); } } /* public static function onLoader(e:Event) { loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onLoader); emptyMc.addChildAt(loader,0); }*/ public static function removeSwf() { if (emptyMc.numChildren!=0) { loader.unloadAndStop(); while (emptyMc.numChildren>0) { emptyMc.removeChildAt(0); } } } //清空emptyMc public static function clearEmpty() { if (ns.time!=0) { ns.close(); emptyMc.removeChild(vid); } if (emptyMc.numChildren!=0) { loader.unloadAndStop(); while (emptyMc.numChildren>0) { emptyMc.removeChildAt(0); } } } public static var lineMcWidth:Number; public static var lineMcX:Number; public static var mcN:uint; public static var bounds:Rectangle; public static var dragMc:MovieClip; public static var lineMc:MovieClip; public static function FlvFun(_dragMc:MovieClip ,_lineMc:MovieClip ,_stageMc:Stage ) { dragMc=_dragMc; lineMc=_lineMc; stageMc=_stageMc; lineMc.stop(); dragMc.x=lineMc.x; dragMc.y=lineMc.y; lineMcX=lineMc.x; bounds=new Rectangle(lineMc.x,lineMc.y,lineMc.width,0); dragMc.buttonMode=true; dragMc.addEventListener(MouseEvent.MOUSE_DOWN,dragFun); dragMc.addEventListener(MouseEvent.MOUSE_UP,dragFun); stageMc.addEventListener(MouseEvent.MOUSE_UP,dragFun); } public static function dragFun(e:MouseEvent):void { if (e.type=="mouseDown") { e.target.startDrag(false,bounds); dragMc.addEventListener(MouseEvent.MOUSE_MOVE,dragFun); timer.stop(); } else if (e.type=="mouseUp") { dragMc.stopDrag(); timer.start(); dragMc.removeEventListener(MouseEvent.MOUSE_MOVE,dragFun); } else if (e.type=="mouseMove") { vidProgressNum=vidTotalTime*(dragMc.x-lineMc.x)/lineMc.width ; ns.seek(vidProgressNum); var i:int=lineMc.totalFrames*(dragMc.x-lineMc.x)/lineMc.width; lineMc.gotoAndStop(i); } } //================togglePause public static var togglePause:MovieClip; public static function togglePauseFun(_togglePause:MovieClip) { togglePause=_togglePause; togglePause.stop(); togglePause.addEventListener(MouseEvent.CLICK,ontogglePause); } public static function ontogglePause(e:MouseEvent) { if (togglePause.currentFrame==1) { togglePause.gotoAndStop(2); } else { togglePause.gotoAndStop(1); } ns.togglePause(); } //声音========================= public static var voiceMc:MovieClip; public static var rec:Rectangle; public static function voiceFun(_voiceMc:MovieClip) { voiceMc=_voiceMc; voiceMc.stop(); voiceMc.addEventListener(MouseEvent.MOUSE_UP ,onVoice); } public static function onVoice(e:MouseEvent ) { if (voiceMc.currentFrame==1) { voiceMc.nextFrame(); soundTF=ns.soundTransform;//控制的目标 soundTF.volume=0;//设置目标的声音为0 ns.soundTransform=soundTF; } else { voiceMc.prevFrame(); soundTF=ns.soundTransform;//控制的目标 soundTF.volume=1;//设置目标的声音为0 ns.soundTransform=soundTF; } } } }
标签:opd simple sim == || .com inf bounds ace
原文地址:https://www.cnblogs.com/zqiang0803/p/10789944.html