From 5168b64a4cc03df532887bfae31ce31d1cbf47c6 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Tue, 3 May 2011 23:00:39 -0700 Subject: [PATCH] make videotube send qte events --- src/EventQte.as | 20 ++++++++++++++++++++ src/Videotube.as | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/EventQte.as diff --git a/src/EventQte.as b/src/EventQte.as new file mode 100644 index 0000000..64ff598 --- /dev/null +++ b/src/EventQte.as @@ -0,0 +1,20 @@ +package +{ + import flash.events.Event; + + /** + * ... + * @author jjp + */ + public class EventQte extends Event + { + public static const QTE:String = "qte"; + public var qte:Qte; + public function EventQte(qte:Qte) + { + super(QTE); + this.qte = qte; + } + } + +} \ No newline at end of file diff --git a/src/Videotube.as b/src/Videotube.as index 43400a8..2ccccd1 100644 --- a/src/Videotube.as +++ b/src/Videotube.as @@ -14,15 +14,21 @@ package private var flv:Video; private var gamedisc:Gamedisc; public var stream:NetStream; + private var iqte:int; + private var secPrev:Number; public function Videotube(gamedisc:Gamedisc) { super(); this.gamedisc = gamedisc; + iqte = 0; + secPrev = 0; addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e: Event):void { removeEventListener(Event.ADDED_TO_STAGE, init); + addEventListener(Event.REMOVED_FROM_STAGE, cleanup); + flv = new Video(stage.stageWidth, stage.stageHeight); addChild(flv); var conn:NetConnection = new NetConnection(); @@ -30,6 +36,39 @@ package stream = new NetStream(conn); stream.client = new Object(); flv.attachNetStream(stream); + + stage.addEventListener(Event.ENTER_FRAME, tick); } + private function cleanup(e: Event):void + { + removeEventListener(Event.REMOVED_FROM_STAGE, cleanup); + stage.removeEventListener(Event.ENTER_FRAME, tick); + } + private function tick(e: Event):void + { + var secNow:Number = stream.time; + if (secNow > secPrev && secPrev >= 0) + { + while(iqte < gamedisc.rgqte.length) + { + var qte:Qte = gamedisc.rgqte[iqte]; + if (qte.secTrigger > secNow) + break; + if (qte.secTrigger > secPrev) + dispatchEvent(new EventQte(qte)); + iqte ++; + } + } + else + { + iqte = 0; + } + secPrev = secNow; + } + public function play():void + { + stream.play(gamedisc.urlVideo); + } + } } \ No newline at end of file