Separate Halcyon (rendering) into standalone target without Flex dependency; JavaScri...
[potlatch2.git] / halcyon_viewer.as
1 package {
2
3         import net.systemeD.halcyon.*;
4         import net.systemeD.halcyon.connection.*;
5         import flash.system.Security;
6         import flash.net.*;
7         import flash.events.*;
8         import flash.events.MouseEvent;
9         import flash.display.*;
10         import flash.text.TextField;
11
12         public class halcyon_viewer extends Sprite {
13
14                 public var theMap:Map;
15
16                 function halcyon_viewer():void {
17                         stage.align = StageAlign.TOP_LEFT;
18                         stage.scaleMode = StageScaleMode.NO_SCALE;
19                         this.loaderInfo.addEventListener(Event.COMPLETE, init);
20                 }
21         
22                 private function init(e:Event):void {
23
24                         // add debug field
25                         var t:TextField=new TextField();
26                         t.width=400; t.height=100; t.x=400; t.border=true;
27                         t.multiline=true;
28                         addChild(t);
29                         Globals.vars.debug=t;
30                         t.visible = true;
31
32                         theMap = new Map(this.loaderInfo.parameters);
33             theMap.updateSize(stage.stageWidth, stage.stageHeight);
34                         addChild(theMap);
35                         Globals.vars.root=theMap;
36
37                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
38                         stage.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
39                         stage.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
40
41                         var z1:Sprite=new Sprite();
42                         z1.graphics.beginFill(0x0000FF); z1.graphics.drawRoundRect(0,0,20,20,5); z1.graphics.endFill();
43                         z1.graphics.lineStyle(2,0xFFFFFF);
44                         z1.graphics.moveTo(5,10); z1.graphics.lineTo(15,10);
45                         z1.graphics.moveTo(10,5); z1.graphics.lineTo(10,15);
46                         z1.x=5; z1.y=5; z1.buttonMode=true;
47                         z1.addEventListener(MouseEvent.CLICK, zoomInHandler, false, 1);
48                         addChild(z1);
49
50                         var z2:Sprite=new Sprite();
51                         z2.graphics.beginFill(0x0000FF); z2.graphics.drawRoundRect(0,0,20,20,5); z2.graphics.endFill();
52                         z2.graphics.lineStyle(2,0xFFFFFF);
53                         z2.graphics.moveTo(5,10); z2.graphics.lineTo(15,10);
54                         z2.x=5; z2.y=30; z2.buttonMode=true;
55                         z2.addEventListener(MouseEvent.CLICK, zoomOutHandler, false, 1);
56                         addChild(z2);
57
58                         if (this.loaderInfo.parameters.hasOwnProperty('responder')) {
59                 var controller:JSController = new JSController(theMap, loaderInfo.parameters['responder']);
60                                 controller.setActive();
61                         }
62                 }
63                 
64                 private function zoomInHandler(e:MouseEvent):void  { e.stopPropagation(); theMap.zoomIn(); }
65                 private function zoomOutHandler(e:MouseEvent):void { e.stopPropagation(); theMap.zoomOut(); }
66         }
67 }