5106e9539eaa52235586da144117c2d98310e460
[potlatch2.git] / net / systemeD / halcyon / connection / AMFCounter.as
1 package net.systemeD.halcyon.connection {
2
3     import flash.events.EventDispatcher;
4     import flash.events.Event;
5         
6         public class AMFCounter extends EventDispatcher {
7                 private var requests:Object;
8                 public var count:uint;
9                 public var eventList:Array;
10                 private var connection:Connection;
11                 
12                 public function AMFCounter(conn:Connection) {
13                         requests={};
14                         count=0;
15                         eventList=[];
16                         connection=conn;
17                 }
18                 
19                 public function addEvent(e:*):void {
20                         eventList.push(e);
21                 }
22                 
23                 public function addRelationRequest(id:uint):void {
24                         addRequest(id+"rel");
25                 }
26                 public function addWayRequest(id:uint):void {
27                         addRequest(id+"way");
28                 }
29                 private function addRequest(n:String):Boolean {
30                         if (requests[n]) { return false; }
31                         requests[n]=true;
32                         count++;
33                         return true;
34                 }
35                 
36                 public function removeRequest(n:String):Boolean {
37                         if (!requests[n]) { return false; }
38                         delete requests[n];
39                         count--; if (count==0) { sendEvents(); }
40                         return true;
41                 }
42                 
43                 private function sendEvents():void {
44                         for each (var e:* in eventList) {
45                                 connection.dispatchEvent(e);
46                         }
47                         this.eventList=[];
48                 }
49         }
50 }