remove a huge load of pseudo-traces
[potlatch2.git] / net / systemeD / halcyon / Map.as
1 package net.systemeD.halcyon {
2
3         import flash.display.Loader;
4         import flash.display.Sprite;
5         import flash.events.*;
6         import flash.external.ExternalInterface;
7         import flash.geom.Rectangle;
8         import flash.net.*;
9         import flash.text.Font;
10         import flash.text.TextField;
11         import flash.ui.Keyboard;
12         
13         import net.systemeD.halcyon.connection.*;
14         import net.systemeD.halcyon.styleparser.*;
15
16 //      for experimental export function:
17 //      import flash.net.FileReference;
18 //      import com.adobe.images.JPGEncoder;
19
20     /** The representation of part of the map on the screen, including information about coordinates, background imagery, paint properties etc. */
21     public class Map extends Sprite {
22
23                 /** master map scale - how many Flash pixels in 1 degree longitude (for Landsat, 5120) */
24                 public const MASTERSCALE:Number=5825.4222222222; 
25                                                                                                 
26                 /** don't zoom out past this */
27                 public const MINSCALE:uint=13; 
28                 /** don't zoom in past this */
29                 public const MAXSCALE:uint=23; 
30
31                 /** sprite for ways and (POI/tagged) nodes in core layer */
32                 public var paint:MapPaint;                                               
33                 /** sprite for vector background layers */
34                 public var vectorbg:Sprite;
35
36                 /** map scale */
37                 public var scale:uint=14;                                                
38                 /** current scaling factor for lon/latp */
39                 public var scalefactor:Number=MASTERSCALE;
40                 public var bigedge_l:Number= 999999;                    // area of largest whichways
41                 public var bigedge_r:Number=-999999;                    //  |
42                 public var bigedge_b:Number= 999999;                    //  |
43                 public var bigedge_t:Number=-999999;                    //  |
44
45                 public var edge_l:Number;                                               // current bounding box
46                 public var edge_r:Number;                                               //  |
47                 public var edge_t:Number;                                               //  |
48                 public var edge_b:Number;                                               //  |
49                 public var centre_lat:Number;                                   // centre lat/lon
50                 public var centre_lon:Number;                                   //  |
51
52                 /** urllon-xradius/masterscale; */ 
53                 public var baselon:Number;
54                 /** lat2lat2p(urllat)+yradius/masterscale; */
55                 public var basey:Number; 
56                 /** width (Flash pixels) */
57                 public var mapwidth:uint; 
58                 /** height (Flash pixels) */
59                 public var mapheight:uint; 
60
61                 /** Is the map being panned */
62                 public var dragstate:uint=NOT_DRAGGING;                 // dragging map (panning)
63                 /** Can the map be panned */
64                 private var _draggable:Boolean=true;                    //  |
65                 private var lastxmouse:Number;                                  //  |
66                 private var lastymouse:Number;                                  //  |
67                 private var downX:Number;                                               //  |
68                 private var downY:Number;                                               //  |
69                 private var downTime:Number;                                    //  |
70                 public const NOT_DRAGGING:uint=0;                               //  |
71                 public const NOT_MOVED:uint=1;                                  //  |
72                 public const DRAGGING:uint=2;                                   //  |
73                 /** How far the map can be dragged without actually triggering a pan. */
74                 public const TOLERANCE:uint=7;                                  //  |
75                 
76                 /** object containing HTML page parameters */
77                 public var initparams:Object; 
78
79                 /** reference to backdrop sprite */
80                 public var backdrop:Object; 
81                 /** background tile object */
82                 public var tileset:TileSet; 
83                 /** background tile URL, name and scheme */
84                 private var tileparams:Object={ url:'' }; 
85                 /** internal style URL */
86                 private var styleurl:String=''; 
87                 /** show all objects, even if unstyled? */
88                 public var showall:Boolean=true; 
89                 
90                 /** server connection */
91                 public var connection:Connection; 
92                 /** VectorLayer objects */
93                 public var vectorlayers:Object={};  
94                 
95                 /** Should the position of mouse cursor be shown to the user? */
96                 private var showingLatLon:Boolean=false;  
97                 
98                 // ------------------------------------------------------------------------------------------
99                 /** Map constructor function */
100         public function Map(initparams:Object) {
101
102                         this.initparams=initparams;
103                         connection = Connection.getConnection(initparams);
104             connection.addEventListener(Connection.NEW_WAY, newWayCreated);
105             connection.addEventListener(Connection.NEW_POI, newPOICreated);
106             connection.addEventListener(Connection.WAY_RENUMBERED, wayRenumbered);
107             connection.addEventListener(Connection.NODE_RENUMBERED, nodeRenumbered);
108                         gotEnvironment(null);
109
110                         addEventListener(Event.ENTER_FRAME, everyFrame);
111                         scrollRect=new Rectangle(0,0,800,600);
112         }
113
114                 public function gotEnvironment(r:Object):void {
115                         var loader:Loader = new Loader();
116                         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotFont);
117                         loader.load(new URLRequest("FontLibrary.swf"));
118                 }
119                 
120                 public function gotFont(r:Event):void {
121                         var FontLibrary:Class = r.target.applicationDomain.getDefinition("FontLibrary") as Class;
122                         Font.registerFont(FontLibrary.DejaVu);
123
124                         if (initparams['lat'] != null) {
125                                 // parameters sent from HTML
126                                 init(initparams['lat'],
127                                          initparams['lon'],
128                                          initparams['zoom']);
129
130                         } else {
131                                 // somewhere innocuous
132                                 init(53.09465,-2.56495,17);
133                         }
134                 }
135
136                 // ------------------------------------------------------------------------------------------
137                 /** Initialise map at a given lat/lon */
138         public function init(startlat:Number, startlon:Number, startscale:uint=0):void {
139                         while (numChildren) { removeChildAt(0); }
140
141                         tileset=new TileSet(this);                                      // 0 - 900913 background
142                         if (initparams['tileblocks']) {                         //   | option to block dodgy tile sources
143                                 tileset.blocks=initparams['tileblocks'];//   |
144                         }                                                                                       //   |
145                         addChild(tileset);                                                      //   |
146                         tileset.init(tileparams, false, 
147                                      initparams['background_dim']    ==null ? true  : initparams['background_dim'],
148                                      initparams['background_sharpen']==null ? false : initparams['background_sharpen']);
149
150                         vectorbg = new Sprite();                                        // 1 - vector background layers
151                         addChild(vectorbg);                                                     //   |
152
153                         paint = new MapPaint(this,-5,5);                        // 2 - core paint object
154                         addChild(paint);                                                        //   |
155                         paint.isBackground=false;                                       //   |
156
157                         if (styleurl) {                                                         // if we've only just set up paint, then setStyle won't have created the RuleSet
158                                 paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
159                                 paint.ruleset.loadFromCSS(styleurl);
160                         }
161                         if (startscale>0) {
162                                 scale=startscale;
163                                 this.dispatchEvent(new MapEvent(MapEvent.SCALE, {scale:scale}));
164                         }
165
166                         scalefactor=MASTERSCALE/Math.pow(2,13-scale);
167                         baselon    =startlon          -(mapwidth /2)/scalefactor;
168                         basey      =lat2latp(startlat)+(mapheight/2)/scalefactor;
169                         updateCoords(0,0);
170             this.dispatchEvent(new Event(MapEvent.INITIALISED));
171                         download();
172
173             if (ExternalInterface.available) {
174               ExternalInterface.addCallback("setPosition", function (lat:Number,lon:Number,zoom:uint):void {
175                   updateCoordsFromLatLon(lat, lon);
176                   changeScale(zoom);
177               });
178             }
179         }
180
181                 // ------------------------------------------------------------------------------------------
182                 /** Recalculate co-ordinates from new Flash origin */
183
184                 public function updateCoords(tx:Number,ty:Number):void {
185                         setScrollRectXY(tx,ty);
186
187                         edge_t=coord2lat(-ty          );
188                         edge_b=coord2lat(-ty+mapheight);
189                         edge_l=coord2lon(-tx          );
190                         edge_r=coord2lon(-tx+mapwidth );
191                         setCentre();
192
193                         tileset.update();
194                 }
195                 
196                 /** Move the map to centre on a given latitude/longitude. */
197                 public function updateCoordsFromLatLon(lat:Number,lon:Number):void {
198                         var cy:Number=-(lat2coord(lat)-mapheight/2);
199                         var cx:Number=-(lon2coord(lon)-mapwidth/2);
200                         updateCoords(cx,cy);
201                 }
202                 
203                 private function setScrollRectXY(tx:Number,ty:Number):void {
204                         var w:Number=scrollRect.width;
205                         var h:Number=scrollRect.height;
206                         scrollRect=new Rectangle(-tx,-ty,w,h);
207                 }
208                 private function setScrollRectSize(width:Number,height:Number):void {
209                         var sx:Number=scrollRect.x ? scrollRect.x : 0;
210                         var sy:Number=scrollRect.y ? scrollRect.y : 0;
211                         scrollRect=new Rectangle(sx,sy,width,height);
212                 }
213                 
214                 private function getX():Number { return -scrollRect.x; }
215                 private function getY():Number { return -scrollRect.y; }
216                 
217                 private function setCentre():void {
218                         centre_lat=coord2lat(-getY()+mapheight/2);
219                         centre_lon=coord2lon(-getX()+mapwidth/2);
220                         this.dispatchEvent(new MapEvent(MapEvent.MOVE, {lat:centre_lat, lon:centre_lon, scale:scale, minlon:edge_l, maxlon:edge_r, minlat:edge_b, maxlat:edge_t}));
221                 }
222                 
223                 /** Sets the offset between the background imagery and the map. */
224                 public function nudgeBackground(x:Number,y:Number):void {
225                         this.dispatchEvent(new MapEvent(MapEvent.NUDGE_BACKGROUND, { x: x, y: y }));
226                 }
227
228                 private function moveMap(dx:Number,dy:Number):void {
229                         updateCoords(getX()+dx,getY()+dy);
230                         updateEntityUIs(false, false);
231                         download();
232                 }
233                 
234                 /** Recentre map at given lat/lon, updating the UI and downloading entities. */
235                 public function moveMapFromLatLon(lat:Number,lon:Number):void {
236                         updateCoordsFromLatLon(lat,lon);
237                         updateEntityUIs(false,false);
238                         download();
239                 }
240                 
241                 /** Recentre map at given lat/lon, if that point is currently outside the visible area. */
242                 public function scrollIfNeeded(lat:Number,lon:Number): void{
243             if (lat> edge_t || lat < edge_b || lon < edge_l || lon > edge_r) {
244                 moveMapFromLatLon(lat, lon);
245             }
246
247                 }
248
249                 // Co-ordinate conversion functions
250
251                 public function latp2coord(a:Number):Number     { return -(a-basey)*scalefactor; }
252                 public function coord2latp(a:Number):Number     { return a/-scalefactor+basey; }
253                 public function lon2coord(a:Number):Number      { return (a-baselon)*scalefactor; }
254                 public function coord2lon(a:Number):Number      { return a/scalefactor+baselon; }
255
256                 public function latp2lat(a:Number):Number       { return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2); }
257                 public function lat2latp(a:Number):Number       { return 180/Math.PI * Math.log(Math.tan(Math.PI/4+a*(Math.PI/180)/2)); }
258
259                 public function lat2coord(a:Number):Number      { return -(lat2latp(a)-basey)*scalefactor; }
260                 public function coord2lat(a:Number):Number      { return latp2lat(a/-scalefactor+basey); }
261
262
263                 // ------------------------------------------------------------------------------------------
264                 /** Resize map size based on current stage and height */
265
266                 public function updateSize(w:uint, h:uint):void {
267                         mapwidth = w; centre_lon=coord2lon(-getX()+w/2);
268                         mapheight= h; centre_lat=coord2lat(-getY()+h/2);
269                         setScrollRectSize(w,h);
270
271                         this.dispatchEvent(new MapEvent(MapEvent.RESIZE, {width:w, height:h}));
272                         
273             if ( backdrop != null ) {
274                 backdrop.width=mapwidth;
275                 backdrop.height=mapheight;
276             }
277             if ( mask != null ) {
278                 mask.width=mapwidth;
279                 mask.height=mapheight;
280             }
281                 }
282
283         /** Download map data. Data is downloaded for the connection and the vector layers, where supported.
284         * The bounding box for the download is taken from the current map edges.
285         */
286                 public function download():void {
287                         this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
288                         
289                         if (edge_l>=bigedge_l && edge_r<=bigedge_r &&
290                                 edge_b>=bigedge_b && edge_t<=bigedge_t) { return; }     // we have already loaded this area, so ignore
291                         bigedge_l=edge_l; bigedge_r=edge_r;
292                         bigedge_b=edge_b; bigedge_t=edge_t;
293                         if (connection.waycount>1000) {
294                                 connection.purgeOutside(edge_l,edge_r,edge_t,edge_b);
295                         }
296                         connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
297
298             // Do the same for vector layers
299             for each (var layer:VectorLayer in vectorlayers) {
300               layer.loadBbox(edge_l,edge_r,edge_t,edge_b);
301             }
302                 }
303
304         private function newWayCreated(event:EntityEvent):void {
305             var way:Way = event.entity as Way;
306                         if (!way.loaded || !way.within(edge_l,edge_r,edge_t,edge_b)) { return; }
307                         paint.createWayUI(way);
308         }
309
310         private function newPOICreated(event:EntityEvent):void {
311             var node:Node = event.entity as Node;
312                         if (!node.within(edge_l,edge_r,edge_t,edge_b)) { return; }
313                         paint.createNodeUI(node);
314         }
315
316                 private function wayRenumbered(event:EntityRenumberedEvent):void {
317             var way:Way = event.entity as Way;
318                         paint.renumberWayUI(way,event.oldID);
319                 }
320
321                 private function nodeRenumbered(event:EntityRenumberedEvent):void {
322             var node:Node = event.entity as Node;
323                         paint.renumberNodeUI(node,event.oldID);
324                 }
325
326         /** Visually mark an entity as highlighted. */
327         public function setHighlight(entity:Entity, settings:Object):void {
328                         if      ( entity is Way  && paint.wayuis[entity.id] ) { paint.wayuis[entity.id].setHighlight(settings);  }
329                         else if ( entity is Node && paint.nodeuis[entity.id]) { paint.nodeuis[entity.id].setHighlight(settings); }
330         }
331
332         public function setHighlightOnNodes(way:Way, settings:Object):void {
333                         if (paint.wayuis[way.id]) paint.wayuis[way.id].setHighlightOnNodes(settings);
334         }
335
336                 public function protectWay(way:Way):void {
337                         if (paint.wayuis[way.id]) paint.wayuis[way.id].protectSprites();
338                 }
339
340                 public function unprotectWay(way:Way):void {
341                         if (paint.wayuis[way.id]) paint.wayuis[way.id].unprotectSprites();
342                 }
343                 
344                 public function limitWayDrawing(way:Way,except:Number=NaN,only:Number=NaN):void {
345                         if (!paint.wayuis[way.id]) return;
346                         paint.wayuis[way.id].drawExcept=except;
347                         paint.wayuis[way.id].drawOnly  =only;
348                         paint.wayuis[way.id].redraw();
349                 }
350
351                 /** Protect Entities and EntityUIs against purging. This prevents the currently selected items
352                    from being purged even though they're off-screen. */
353
354                 public function setPurgable(entities:Array, purgable:Boolean):void {
355                         for each (var entity:Entity in entities) {
356                                 entity.locked=!purgable;
357                                 if ( entity is Way  ) {
358                                         var way:Way=entity as Way;
359                                         if (paint.wayuis[way.id]) { paint.wayuis[way.id].purgable=purgable; }
360                                         for (var i:uint=0; i<way.length; i++) {
361                                                 var node:Node=way.getNode(i)
362                                                 node.locked=!purgable;
363                                                 if (paint.nodeuis[node.id]) { paint.nodeuis[node.id].purgable=purgable; }
364                                         }
365                                 } else if ( entity is Node && paint.nodeuis[entity.id]) { 
366                                         paint.nodeuis[entity.id].purgable=purgable;
367                                 }
368                         }
369                 }
370
371         // Handle mouse events on ways/nodes
372         private var mapController:MapController = null;
373
374         /** Assign map controller. */
375         public function setController(controller:MapController):void {
376             this.mapController = controller;
377         }
378
379         public function entityMouseEvent(event:MouseEvent, entity:Entity):void {
380             if ( mapController != null )
381                 mapController.entityMouseEvent(event, entity);
382                                 
383         }
384
385                 // ------------------------------------------------------------------------------------------
386                 // Add vector layer
387                 
388                 public function addVectorLayer(layer:VectorLayer):void {
389                         vectorlayers[layer.name]=layer;
390                         vectorbg.addChild(layer.paint);
391                 }
392
393                 // ------------------------------------------------------------------------------------------
394                 // Redraw all items, zoom in and out
395                 
396                 public function updateEntityUIs(redraw:Boolean,remove:Boolean):void {
397                         paint.updateEntityUIs(connection.getObjectsByBbox(edge_l, edge_r, edge_t, edge_b), redraw, remove);
398                         for each (var v:VectorLayer in vectorlayers) {
399                                 v.paint.updateEntityUIs(v.getObjectsByBbox(edge_l, edge_r, edge_t, edge_b), redraw, remove);
400                         }
401                 }
402                 /** Redraw everything, including in every vector layer. */
403                 public function redraw():void {
404                         paint.redraw();
405                         for each (var v:VectorLayer in vectorlayers) { v.paint.redraw(); }
406                 }
407                 /** Redraw POI's, including in every vector layer. */
408                 public function redrawPOIs():void { 
409                         paint.redrawPOIs();
410                         for each (var v:VectorLayer in vectorlayers) { v.paint.redrawPOIs(); }
411                 }
412                 
413                 /** Increase scale. */
414                 public function zoomIn():void {
415                         if (scale==MAXSCALE) { return; }
416                         changeScale(scale+1);
417                 }
418
419                 /** Decrease scale. */
420                 public function zoomOut():void {
421                         if (scale==MINSCALE) { return; }
422                         changeScale(scale-1);
423                 }
424
425                 private function changeScale(newscale:uint):void {
426                         scale=newscale;
427                         this.dispatchEvent(new MapEvent(MapEvent.SCALE, {scale:scale}));
428                         scalefactor=MASTERSCALE/Math.pow(2,13-scale);
429                         updateCoordsFromLatLon((edge_t+edge_b)/2,(edge_l+edge_r)/2);    // recentre
430                         tileset.changeScale(scale);
431                         updateEntityUIs(true,true);
432                         download();
433                 }
434
435         private function toggleReportPosition():void {
436             showingLatLon = !showingLatLon;
437             this.dispatchEvent(new MapEvent(MapEvent.TOGGLE_LATLON, {latlon: showingLatLon}));
438         }
439                 
440                 /** Switch to new MapCSS. */
441                 public function setStyle(url:String):void {
442                         styleurl=url;
443                         if (paint) { 
444                                 paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
445                                 paint.ruleset.loadFromCSS(url);
446                         }
447         }
448
449                 /** Select a new background imagery. */
450                 public function setBackground(bg:Object):void {
451                         tileparams=bg;
452                         if (tileset) { tileset.init(bg, bg.url!=''); }
453                 }
454
455                 /** Set background dimming on/off. */
456                 public function setDimming(dim:Boolean):void {
457                         if (tileset) { tileset.setDimming(dim); }
458                 }
459                 
460                 /** Return background dimming. */
461                 public function getDimming():Boolean {
462                         if (tileset) { return tileset.getDimming(); }
463                         return true;
464                 }
465
466                 /** Set background sharpening on/off. */
467                 public function setSharpen(sharpen:Boolean):void {
468                         if (tileset) { tileset.setSharpen(sharpen); }
469                 }
470                 /** Return background sharpening. */
471                 public function getSharpen():Boolean {
472                         if (tileset) { return tileset.getSharpen(); }
473                         return false;
474                 }
475
476                 // ------------------------------------------------------------------------------------------
477                 // Export (experimental)
478                 // ** just a bit of fun for now!
479                 // really needs to take a bbox, and make sure that the image is correctly cropped/resized 
480                 // to that area (will probably require creating a new DisplayObject with a different origin
481                 // and mask)
482 /*              
483                 public function export():void {
484                         trace("size is "+this.width+","+this.height);
485                         var jpgSource:BitmapData = new BitmapData(800,800); // (this.width, this.height);
486                         jpgSource.draw(this);
487                         var jpgEncoder:JPGEncoder = new JPGEncoder(85);
488                         var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
489                         var fileRef:FileReference = new FileReference();
490 //                      fileRef.save(jpgStream,'map.jpeg');
491                 }
492
493 */
494
495                 // ==========================================================================================
496                 // Events
497                 
498                 // ------------------------------------------------------------------------------------------
499                 // Mouse events
500                 
501                 /** Should map be allowed to pan? */
502                 public function set draggable(draggable:Boolean):void {
503                         _draggable=draggable;
504                         dragstate=NOT_DRAGGING;
505                 }
506
507                 /** Prepare for being dragged by recording start time and location of mouse. */
508                 public function mouseDownHandler(event:MouseEvent):void {
509                         if (!_draggable) { return; }
510                         dragstate=NOT_MOVED;
511                         lastxmouse=stage.mouseX; downX=stage.mouseX;
512                         lastymouse=stage.mouseY; downY=stage.mouseY;
513                         downTime=new Date().getTime();
514                 }
515         
516                 /** Respond to mouse up by possibly moving map. */
517                 public function mouseUpHandler(event:MouseEvent=null):void {
518                         if (dragstate==DRAGGING) { moveMap(x,y); }
519                         dragstate=NOT_DRAGGING;
520                 }
521         
522                 /** Respond to mouse movement, dragging the map if tolerance threshold met. */
523                 public function mouseMoveHandler(event:MouseEvent):void {
524                         if (!_draggable) { return; }
525                         if (dragstate==NOT_DRAGGING) { 
526                            this.dispatchEvent(new MapEvent(MapEvent.MOUSEOVER, { x: coord2lon(mouseX), y: coord2lat(mouseY) }));
527                return; 
528             }
529                         
530                         if (dragstate==NOT_MOVED) {
531                                 if (new Date().getTime()-downTime<300) {
532                                         if (Math.abs(downX-stage.mouseX)<=TOLERANCE   && Math.abs(downY-stage.mouseY)<=TOLERANCE  ) return;
533                                 } else {
534                                         if (Math.abs(downX-stage.mouseX)<=TOLERANCE/2 && Math.abs(downY-stage.mouseY)<=TOLERANCE/2) return;
535                                 }
536                                 dragstate=DRAGGING;
537                         }
538                         
539                         setScrollRectXY(getX()+stage.mouseX-lastxmouse,getY()+stage.mouseY-lastymouse);
540                         lastxmouse=stage.mouseX; lastymouse=stage.mouseY;
541                         setCentre();
542                 }
543         
544                 // ------------------------------------------------------------------------------------------
545                 // Do every frame
546
547                 private function everyFrame(event:Event):void {
548                         if (tileset) { tileset.serviceQueue(); }
549                 }
550
551                 // ------------------------------------------------------------------------------------------
552                 // Miscellaneous events
553                 
554                 /** Respond to cursor movements and zoom in/out.*/
555                 public function keyUpHandler(event:KeyboardEvent):void {
556                         if (event.target is TextField) return;                          // not meant for us
557                         switch (event.keyCode) {
558                                 case Keyboard.PAGE_UP:  zoomIn(); break;                 // Page Up - zoom in
559                                 case Keyboard.PAGE_DOWN:        zoomOut(); break;            // Page Down - zoom out
560                                 case Keyboard.LEFT:     moveMap(mapwidth/2,0); break;        // left cursor
561                                 case Keyboard.UP:       moveMap(0,mapheight/2); break;           // up cursor
562                                 case Keyboard.RIGHT:    moveMap(-mapwidth/2,0); break;   // right cursor
563                                 case Keyboard.DOWN:     moveMap(0,-mapheight/2); break;      // down cursor
564                                 case 76:        toggleReportPosition(); break;                  // L - report lat/long
565                         }
566                 }
567
568                 // ------------------------------------------------------------------------------------------
569                 // Debugging
570                 
571                 public function clearDebug():void {
572                         if (!Globals.vars.hasOwnProperty('debug')) return;
573                         Globals.vars.debug.text='';
574                 }
575                         
576                 public function addDebug(text:String):void {
577                         trace(text);
578                         if (!Globals.vars.hasOwnProperty('debug')) return;
579                         if (!Globals.vars.debug.visible) return;
580                         Globals.vars.debug.appendText(text+"\n");
581                         Globals.vars.debug.scrollV=Globals.vars.debug.maxScrollV;
582                 }
583
584         }
585 }