Extending the TileMap & some components

So we had an issue arrise.  Well we always have issues, but this time it was very needed.  We have users that need to manipulate a group of polygon overlays all at one time.  So we needed a fun little package to put them in.  We added this cool new Object that just Extended the Polygon Overlay.  This worked out handy to package them up, but then we needed a way to quickly work with them and add them to the map, move them off at the same time, or do other things of this nature as a collective group.  So we Extended the TileMap.  This was easy and all we did was to make a couple of functions that would take the New Object that we made and apply all the overlays that were in the object to the map.  This worked out really well.  So now we can add and remove them.  But we also have another problem.

The tilemap has Overlays and they have a Key.  This is good, but the key can be the same, and if you use the function getByKey, it would only return you one, of the possibly many items that were there.  Not good for us, or anyone really, but we needed to fix this.  Well since we are working with our own object, then we can go ahead and write it so we do something like this.

A new Shape Collection which has a function like this:

 public function getMultipleByKey(key:String):Array
{
      var a:Array = new Array();
      var i:int = 0;

      if(this.sc.get(0) is PolygonOverlay)
      {
            for(i=0; i<this.sc.getSize(); i++)
            {
                          if(PolygonOverlay(this.sc.get(i)).getKey() == key)
                                     a.push(PolygonOverlay(this.sc.get(i)));
             }
         }

          if(this.sc.get(0) is Poi)
         {
                 for(i=0; i<this.sc.getSize(); i++)
                 {
                          if(Poi(this.sc.get(i)).getKey() == key)
                                    a.push(Poi(this.sc.get(i)));
                   }
           }

 return a
}

So in the case above, we can call this function and it will get us a shape collection of the multiple items that we wanted.  You don’t have to extend the map to get this functionality, just the ShapeCollection.  We extended a few of the common object we use readily.  This is one of the many things that we have done.  I will try to post some more about what we have done as i see the community might like to know.

Respond to this post