Using an Object as a Lookup Key with Dictionaries : Dictionary « Array « Flash / Flex / ActionScript






Using an Object as a Lookup Key with Dictionaries

 

package{
  import flash.display.Sprite;
  import flash.utils.*

  public class Main extends Sprite{
    public function Main(){

        var notes:Dictionary = new Dictionary();
        var city:String = "New York City";
        var currentConditions:String = "light showers";
        var currentTemp:Number = 56;
        
        notes[city] = "Central Park";
        notes[currentTemp] = "20";
        notes[currentConditions] = "70% chance of precipitation";
        
        trace("Current Weather for", city, notes[city]);
        trace("Current Temperature :", currentTemp, "degrees", notes[currentTemp]);
        trace("Current Conditions :", currentConditions, "(", notes[currentConditions],")");
    }
  }
}

        








Related examples in the same category

1.Working with Associative Arrays
2.When using delete on an item in an Array, the length property is not updated.
3.Iterate through the key-value pairs of an object with the for..in and for each..in loops.