2014-11-03 77 views
1

我正在復活一個簡單的橫幅,我們使用FLV電影和下面的代碼讓電影使用setInterval暫停,然後再次播放。這是一個簡單的蝴蝶電影,掀起它的翅膀,然後回到靜態。如何顯示mp4然後暫停並在Flash中重播CC

看起來像現在的FLV在最近的Flash版本中是不鼓勵的,所以我想知道如何製作電影,然後使用setInterval暫停,然後重播。

這裏的工作AS3使用FLV時,在基於幀的動畫時間軸,但不與導入的.MP4工作:

stop(); 
function timesUp() 
{ 
gotoAndPlay(1,"Scene 1"); 
clearInterval(itv); 
} 
var itv=setInterval(timesUp, 15000); 

做新建議的方法使用單個幀的電影在那裏你加載並播放mp4,然後使用setInterval作爲定時器重播?

我找不到任何有此方法的教程爲例。

我沒有閱讀Adobe網站的教程,但下面沒有加載和播放電影(morpho.mp4)

var nc:NetConnection = new NetConnection(); 
nc.connect(null); 
var vid:Video = new Video(); 
addChild(vid); 
var ns:NetStream = new NetStream(nc); 
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

function netStatusHandler(event:NetStatusEvent):void 
{ 
// handle netStatus events, described later 
} 

function asyncErrorHandler(event:AsyncErrorEvent):void 
{ 
// ignore error 
} 
vid.attachNetStream(ns); 

ns.play("morpho.mp4"); 
+0

我測試你的代碼,它工作沒有問題。你可以添加'trace(event.info.code)'到'netStatusHandler'中,可以通過你的視頻找不到。 – akmozo 2014-11-03 16:03:37

+0

akmzo - 你是對的。謝謝。我添加了顯示.mp4不在電影相同/根目錄中的跟蹤。它可以顯示整個舞臺,並將下一個問題轉化爲如何整合setInterval和replay? – Burndogz 2014-11-03 16:14:29

+0

我試圖做你正在尋找的東西。 – akmozo 2014-11-03 17:07:29

回答

0

試試這個:

import flash.utils.Timer 
import flash.events.TimerEvent 

var video_playing:Boolean = false, 
    timer:Timer, 
    nc:NetConnection, 
    ns:NetStream, 
    video:Video, 
    video_name:String = 'video.mp4' 

nc = new NetConnection() 
nc.connect(null) 

ns = new NetStream(nc) 
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

function netStatusHandler(event:NetStatusEvent):void {  
    switch (event.info.code){ 
     case 'NetStream.Play.Start' : 
      if(timer.currentCount == 0){ 
       timer.start() 
      } 
     break  
    } 
} 
function asyncErrorHandler(event:AsyncErrorEvent):void { 
} 

video = new Video(135, 135) // set the size of video to 135x135px 
video.x = 165    // set the left of video to 300 - 135 = 165px 
video.y = 0     // set the top of video to 0 
video.attachNetStream(ns) 
addChild(video) 

timer = new Timer(1000, 3) // 3 seconds, just for example 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_on_Complete) 
function timer_on_Complete(e:TimerEvent){ 
    if(video_playing){ 
     video_playing = false 
     ns.close() 
    } else { 
     start_video() 
    } 
    timer.reset() 
    timer.start() 
} 

start_video() 

function start_video(){ 
    ns.play(video_name) 
    video_playing = true 
} 
+0

akmozo - 完美的作品。謝謝。 問題:mp4的135 x 135位於300 x 135舞臺的右側。我在時間軸上有一個左側標誌,但現在mp4覆蓋了這個標誌。我應該探索哪些代碼來學習如何確定mp4的大小和位置? – Burndogz 2014-11-03 21:00:40

+0

我編輯了我的答案。 – akmozo 2014-11-03 21:11:09

+0

非常棒!我學到了很多。 – Burndogz 2014-11-03 22:08:29