move lots of eventListeners to weak references; fix a few dodgy (or non-existent...
authorRichard Fairhurst <richard@systemed.net>
Sat, 22 Jan 2011 22:27:16 +0000 (22:27 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sat, 22 Jan 2011 22:27:16 +0000 (22:27 +0000)
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/MarkerUI.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Trace.as
net/systemeD/halcyon/styleparser/Eval.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/mapfeatures/editors/RelationMemberEditor.as
net/systemeD/potlatch2/mapfeatures/editors/RouteEditor.mxml

index 0f12102..7fddf78 100644 (file)
@@ -58,18 +58,18 @@ package net.systemeD.halcyon {
                public function EntityUI(entity:Entity, paint:MapPaint) {
                        this.entity=entity;
                        this.paint=paint;
-            entity.addEventListener(Connection.TAG_CHANGED, tagChanged);
-                       entity.addEventListener(Connection.ADDED_TO_RELATION, relationAdded);
-                       entity.addEventListener(Connection.REMOVED_FROM_RELATION, relationRemoved);
-                       entity.addEventListener(Connection.SUSPEND_REDRAW, suspendRedraw);
-                       entity.addEventListener(Connection.RESUME_REDRAW, resumeRedraw);
-                       listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.ROLL_OVER, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.MOUSE_UP, mouseEvent);
-                       listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
+            entity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
+                       entity.addEventListener(Connection.ADDED_TO_RELATION, relationAdded, false, 0, true);
+                       entity.addEventListener(Connection.REMOVED_FROM_RELATION, relationRemoved, false, 0, true);
+                       entity.addEventListener(Connection.SUSPEND_REDRAW, suspendRedraw, false, 0, true);
+                       entity.addEventListener(Connection.RESUME_REDRAW, resumeRedraw, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.CLICK, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.ROLL_OVER, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.MOUSE_UP, mouseEvent, false, 0, true);
+                       listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent, false, 0, true);
                }
 
                /** Remove the default event listeners. */
@@ -94,12 +94,19 @@ package net.systemeD.halcyon {
                protected function attachRelationListeners():void {
                    var relations:Array = entity.parentRelations;
             for each(var relation:Relation in relations ) {
-                relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
+                relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged, false, 0, true);
+            }
+               }
+
+               protected function removeRelationListeners():void {
+                       var relations:Array = entity.parentRelations;
+            for each(var relation:Relation in relations) {
+                relation.removeEventListener(Connection.TAG_CHANGED, relationTagChanged);
             }
                }
 
                protected function relationAdded(event:RelationMemberEvent):void {
-                   event.relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
+                   event.relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged, false, 0, true);
                        invalidateStyleList();
                    redraw();
                }
index f68725d..bf91c3d 100644 (file)
@@ -251,8 +251,8 @@ package net.systemeD.halcyon {
 
                /** Remove a node's UI object. */
                public function deleteNodeUI(node:Node):void {
-                       if (!nodeuis[node.id]) { return; }
                        node.removeEventListener(Connection.NODE_DELETED, nodeDeleted);
+                       if (!nodeuis[node.id]) { return; }
                        nodeuis[node.id].removeSprites();
                        nodeuis[node.id].removeEventListeners();
                        delete nodeuis[node.id];
@@ -279,8 +279,8 @@ package net.systemeD.halcyon {
 
         /** Remove a marker's UI object. */
         public function deleteMarkerUI(marker:Marker):void {
-            if (!markeruis[marker.id]) { return; }
             marker.removeEventListener(Connection.NODE_DELETED, markerDeleted);
+            if (!markeruis[marker.id]) { return; }
             markeruis[marker.id].removeSprites();
             markeruis[marker.id].removeEventListeners();
             delete markeruis[marker.id];
index 8f6c319..834c42d 100644 (file)
@@ -29,8 +29,8 @@ package net.systemeD.halcyon {
                     if (stateClasses[state]) { this.stateClasses[state]=stateClasses[state]; }
                 }
             }
-            entity.addEventListener(Connection.NODE_MOVED, markerMoved);
-            entity.addEventListener(Connection.NODE_ALTERED, markerAltered);
+            entity.addEventListener(Connection.NODE_MOVED, markerMoved, false, 0, true);
+            entity.addEventListener(Connection.NODE_ALTERED, markerAltered, false, 0, true);
             attachRelationListeners();
             redraw();
         }
@@ -107,7 +107,7 @@ package net.systemeD.halcyon {
                             // 'load' icon (actually just from library)
                             var loader:ExtendedLoader = new ExtendedLoader();
                             loader.info['sublayer']=sublayer;
-                            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
+                            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon, false, 0, true);
                             loader.loadBytes(paint.ruleset.images[s.icon_image]);
                             iconnames[sublayer]=s.icon_image;
                         }
index 3a26003..075b329 100644 (file)
@@ -36,9 +36,9 @@ package net.systemeD.halcyon {
                                        if (stateClasses[state]) { this.stateClasses[state]=stateClasses[state]; }
                                }
                        }
-                       entity.addEventListener(Connection.NODE_MOVED, nodeMoved);
-            entity.addEventListener(Connection.NODE_ALTERED, nodeAltered);
-            entity.addEventListener(Connection.ENTITY_DRAGGED, nodeDragged);
+                       entity.addEventListener(Connection.NODE_MOVED, nodeMoved, false, 0, true);
+            entity.addEventListener(Connection.NODE_ALTERED, nodeAltered, false, 0, true);
+            entity.addEventListener(Connection.ENTITY_DRAGGED, nodeDragged, false, 0, true);
             attachRelationListeners();
                        redraw();
                }
@@ -48,6 +48,7 @@ package net.systemeD.halcyon {
                        entity.removeEventListener(Connection.NODE_MOVED, nodeMoved);
             entity.removeEventListener(Connection.NODE_ALTERED, nodeAltered);
             entity.removeEventListener(Connection.ENTITY_DRAGGED, nodeDragged);
+                       removeRelationListeners();
                }
 
                /** Respond to movement event. */
@@ -124,7 +125,7 @@ package net.systemeD.halcyon {
                                                        // 'load' icon (actually just from library)
                                                        var loader:ExtendedLoader = new ExtendedLoader();
                                                        loader.info['sublayer']=sublayer;
-                                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
+                                                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon, false, 0, true);
                                                        loader.loadBytes(paint.ruleset.images[s.icon_image]);
                                                        iconnames[sublayer]=s.icon_image;
                                                }
index d3853a7..62c16f7 100644 (file)
@@ -39,10 +39,10 @@ package net.systemeD.halcyon {
 
                public function WayUI(way:Way, paint:MapPaint) {
                        super(way,paint);
-            entity.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
-            entity.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
-            entity.addEventListener(Connection.WAY_REORDERED, wayReordered);
-            entity.addEventListener(Connection.ENTITY_DRAGGED, wayDragged);
+            entity.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded, false, 0, true);
+            entity.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved, false, 0, true);
+            entity.addEventListener(Connection.WAY_REORDERED, wayReordered, false, 0, true);
+            entity.addEventListener(Connection.ENTITY_DRAGGED, wayDragged, false, 0, true);
             attachNodeListeners();
             attachRelationListeners();
             recalculate();
@@ -56,20 +56,26 @@ package net.systemeD.halcyon {
             entity.removeEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
             entity.removeEventListener(Connection.WAY_REORDERED, wayReordered);
             entity.removeEventListener(Connection.ENTITY_DRAGGED, wayDragged);
-            for (var i:uint = 0; i < Way(entity).length; i++ ) {
-                Way(entity).getNode(i).removeEventListener(Connection.NODE_MOVED, nodeMoved);
-            }
+                       removeNodeListeners();
+                       removeRelationListeners();
                }
                
                private function attachNodeListeners():void {
                        var way:Way=entity as Way;
             for (var i:uint = 0; i < way.length; i++ ) {
-                way.getNode(i).addEventListener(Connection.NODE_MOVED, nodeMoved);
+                way.getNode(i).addEventListener(Connection.NODE_MOVED, nodeMoved, false, 0, true);
+            }
+               }
+               
+               private function removeNodeListeners():void {
+                       var way:Way=entity as Way;
+            for (var i:uint = 0; i < way.length; i++ ) {
+                way.getNode(i).removeEventListener(Connection.NODE_MOVED, nodeMoved);
             }
                }
                
                private function wayNodeAdded(event:WayNodeEvent):void {
-                   event.node.addEventListener(Connection.NODE_MOVED, nodeMoved);
+                   event.node.addEventListener(Connection.NODE_MOVED, nodeMoved, false, 0, true);
             recalculate();
                    redraw();
                        redrawMultis();
index 2986f1d..55baa01 100644 (file)
@@ -95,6 +95,7 @@ package net.systemeD.halcyon.connection {
         }
 
         private function processEvent(e:Event):void {
+            removeEventListener("loaded_data", processEvent);
             process();
         }
 
index c11ecb9..c8c1095 100644 (file)
@@ -28,7 +28,7 @@ package net.systemeD.halcyon.styleparser {
                        var compiled:CompiledExpression=parser.parse();
                        var swfdata:ByteArray=compiled.compile();
 
-                       this.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
+                       this.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded, false, 0, true);
                        this.loadBytes(swfdata, new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain)));
                }
                
index 81232be..9ba07cc 100644 (file)
@@ -434,7 +434,7 @@ package net.systemeD.halcyon.styleparser {
                private function saveEval(expr:String):Eval {
                        evalsToLoad++;
                        var e:Eval=new Eval(expr);
-                       e.addEventListener("swf_loaded",evalLoaded);
+                       e.addEventListener("swf_loaded",evalLoaded, false, 0, true);
                        evals.push(e);
                        return e;
                }
index 90bc81e..37c825f 100644 (file)
@@ -29,8 +29,6 @@ package net.systemeD.potlatch2.controller {
                                lastClick=way.getNode(0);
                                lastClickTime=new Date();
                        }
-            way.addEventListener(Connection.WAY_NODE_REMOVED, fixElastic);
-            way.addEventListener(Connection.WAY_NODE_ADDED, fixElastic);
                }
                
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
@@ -264,6 +262,9 @@ package net.systemeD.potlatch2.controller {
                override public function enterState():void {
                        super.enterState();
                        
+            Way(firstSelected).addEventListener(Connection.WAY_NODE_REMOVED, fixElastic);
+            Way(firstSelected).addEventListener(Connection.WAY_NODE_ADDED, fixElastic);
+
                        var node:Node = Way(firstSelected).getNode(editEnd ? Way(firstSelected).length-1 : 0);
                        var start:Point = new Point(node.lon, node.latp);
                        elastic = new Elastic(controller.map, start, start);
@@ -271,6 +272,9 @@ package net.systemeD.potlatch2.controller {
                        Globals.vars.root.addDebug("**** -> "+this);
                }
                override public function exitState(newState:ControllerState):void {
+            Way(firstSelected).removeEventListener(Connection.WAY_NODE_REMOVED, fixElastic);
+            Way(firstSelected).removeEventListener(Connection.WAY_NODE_ADDED, fixElastic);
+
                        super.exitState(newState);
                        controller.setCursor(null);
                        elastic.removeSprites();
index 9b35052..86947ba 100644 (file)
@@ -64,8 +64,8 @@ package net.systemeD.potlatch2.mapfeatures.editors {
       public function set entity(entity:Entity):void {
           _entity = entity;
           
-          entity.addEventListener(Connection.ADDED_TO_RELATION, relationsChanged);
-          entity.addEventListener(Connection.REMOVED_FROM_RELATION, relationsChanged);
+          entity.addEventListener(Connection.ADDED_TO_RELATION, relationsChanged, false, 0, true);
+          entity.addEventListener(Connection.REMOVED_FROM_RELATION, relationsChanged, false, 0, true);
           dispatchEvent(new Event("relations_changed"));
       }
       
index 9d7d225..d773ba6 100644 (file)
@@ -25,7 +25,7 @@
             var icon:RouteIcon = new RouteIcon();
             icon.setRoute(relation, RouteEditorFactory(_factory).icon);
             
-            icon.addEventListener(MouseEvent.CLICK, routeClicked);
+            icon.addEventListener(MouseEvent.CLICK, routeClicked, false, 0, true);
             routeIcons.addChild(icon);
         }
     }