Dictionary class in as3.0

[ 2009-05-29 23:10:51 | Author: liuhuan ]
Font Size: Large | Medium | Small
In as3.0, we can easily use the Dictionary class to store a set of information which is much more convenience than Array.
var myDict:Dictionary = new Dictionary();
for (var i:Number=0; i<10; i++) {
  var ms:Sprite = new Sprite();
  var round:Shape = new Shape();
  round.graphics.beginFill(0xFF0000);
  round.graphics.drawCircle(i*35+30,120,15);
  round.graphics.endFill();
  ms.addChild(round);
  this.addChild(ms);
  ms.addEventListener(MouseEvent.MOUSE_DOWN, onMDown)
  myDict[ms] = "unclicked"
}
function onMDown(e:MouseEvent){
  var ms:Sprite = Sprite(e.target)
  if(myDict[ms] == "unclicked"){
    ms.alpha -= .4
    myDict[ms] = "clicked"
  }
}

To remove any key from Dictionary, use delete method.
ms= null;
delete myDict[ms];
Comments Feed Comments Feed: http://www.liuhuan.com/blog/feed.asp?q=comment&id=979

There is no comment on this article.

You can't post comment on this article.