move editor into its own class

This commit is contained in:
Jeremy Penner 2011-05-03 22:27:01 -07:00
parent bd6602a061
commit a0028fbea0
3 changed files with 68 additions and 26 deletions

57
src/GameEditor.as Normal file
View file

@ -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();
}
}
}

View file

@ -11,14 +11,14 @@ package
*/ */
public class Main extends Sprite public class Main extends Sprite
{ {
private var clickarea:ClickArea;
private var sketchShape:SketchShape;
private var videotube:Videotube; private var videotube:Videotube;
private var gamedisc:Gamedisc;
private var gameeditor:GameEditor;
public function Main():void public function Main():void
{ {
clickarea = new ClickArea([new Point(50, 50), new Point(100, 80), new Point(30, 120)], 0x555555); gamedisc = new Gamedisc("The Last Eichhof - Longplay.flv");
sketchShape = new SketchShape(); videotube = new Videotube(gamedisc);
videotube = new Videotube();
if (stage) init(); if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init); else addEventListener(Event.ADDED_TO_STAGE, init);
} }
@ -27,27 +27,10 @@ package
{ {
removeEventListener(Event.ADDED_TO_STAGE, init); removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point // entry point
gameeditor = new GameEditor(videotube, gamedisc);
addChild(videotube); addChild(videotube);
addChild(clickarea); addChild(gameeditor);
addChild(sketchShape); videotube.stream.play(gamedisc.urlVideo);
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();
} }
} }
} }

View file

@ -12,10 +12,12 @@ package
public class Videotube extends Sprite public class Videotube extends Sprite
{ {
private var flv:Video; private var flv:Video;
private var gamedisc:Gamedisc;
public var stream:NetStream; public var stream:NetStream;
public function Videotube() public function Videotube(gamedisc:Gamedisc)
{ {
super(); super();
this.gamedisc = gamedisc;
addEventListener(Event.ADDED_TO_STAGE, init); addEventListener(Event.ADDED_TO_STAGE, init);
} }
private function init(e: Event):void private function init(e: Event):void