From a0028fbea03696a091aea7f49e8f02c6256afd65 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Tue, 3 May 2011 22:27:01 -0700 Subject: [PATCH] move editor into its own class --- src/GameEditor.as | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/Main.as | 33 +++++++-------------------- src/Videotube.as | 4 +++- 3 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 src/GameEditor.as diff --git a/src/GameEditor.as b/src/GameEditor.as new file mode 100644 index 0000000..125878b --- /dev/null +++ b/src/GameEditor.as @@ -0,0 +1,57 @@ +package +{ + import flash.display.Sprite; + import flash.events.Event; + import flash.events.KeyboardEvent; + import flash.events.MouseEvent; + /** + * ... + * @author jjp + */ + public class GameEditor extends Sprite + { + private var videotube:Videotube; + private var gamedisc:Gamedisc; + private var sketchShape:SketchShape; + + public function GameEditor(videotube:Videotube, gamedisc:Gamedisc) + { + this.videotube = videotube; + this.gamedisc = gamedisc; + addEventListener(Event.ADDED_TO_STAGE, init); + } + public function init(e: Event):void + { + removeEventListener(Event.ADDED_TO_STAGE, init); + addEventListener(Event.REMOVED_FROM_STAGE, cleanup); + stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); + + sketchShape = new SketchShape(); + addChild(sketchShape); + sketchShape.addEventListener(SketchShape.DRAW_BEGIN, onDrawBegin); + sketchShape.addEventListener(SketchShape.DRAW_END, onDrawEnd); + } + public function cleanup(e: Event):void + { + removeEventListener(Event.REMOVED_FROM_STAGE, cleanup); + stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp); + sketchShape.removeEventListener(SketchShape.DRAW_BEGIN, onDrawBegin); + sketchShape.removeEventListener(SketchShape.DRAW_END, onDrawEnd); + } + public function onKeyUp(key: KeyboardEvent):void + { + + } + private function onDrawBegin(e: Event): void + { + videotube.stream.pause(); + } + private function onDrawEnd(e: Event): void + { + gamedisc.AddQte(new Qte(sketchShape.rgpoint, videotube.stream.time)); + videotube.stream.resume(); + } + + } + +} \ No newline at end of file diff --git a/src/Main.as b/src/Main.as index 657018a..dac4d19 100644 --- a/src/Main.as +++ b/src/Main.as @@ -11,14 +11,14 @@ package */ public class Main extends Sprite { - private var clickarea:ClickArea; - private var sketchShape:SketchShape; private var videotube:Videotube; + private var gamedisc:Gamedisc; + private var gameeditor:GameEditor; + public function Main():void { - clickarea = new ClickArea([new Point(50, 50), new Point(100, 80), new Point(30, 120)], 0x555555); - sketchShape = new SketchShape(); - videotube = new Videotube(); + gamedisc = new Gamedisc("The Last Eichhof - Longplay.flv"); + videotube = new Videotube(gamedisc); if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } @@ -27,27 +27,10 @@ package { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point + gameeditor = new GameEditor(videotube, gamedisc); addChild(videotube); - addChild(clickarea); - addChild(sketchShape); - addEventListener(MouseEvent.CLICK, onClick); - sketchShape.addEventListener(SketchShape.DRAW_BEGIN, onShapeBegin); - sketchShape.addEventListener(SketchShape.DRAW_END, onShapeComplete); - videotube.stream.play("The Last Eichhof - Longplay.flv"); - } - private function onClick(e: MouseEvent): void - { - if (clickarea.FHit(new Point(e.stageX, e.stageY))) - clickarea.Toggle(); - } - private function onShapeBegin(e: Event): void - { - videotube.stream.pause(); - } - private function onShapeComplete(e: Event): void - { - addChild(new ClickArea(sketchShape.rgpoint, 0x883388, 0.5)); - videotube.stream.resume(); + addChild(gameeditor); + videotube.stream.play(gamedisc.urlVideo); } } } \ No newline at end of file diff --git a/src/Videotube.as b/src/Videotube.as index d159043..43400a8 100644 --- a/src/Videotube.as +++ b/src/Videotube.as @@ -12,10 +12,12 @@ package public class Videotube extends Sprite { private var flv:Video; + private var gamedisc:Gamedisc; public var stream:NetStream; - public function Videotube() + public function Videotube(gamedisc:Gamedisc) { super(); + this.gamedisc = gamedisc; addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e: Event):void