Posted By

adrianparr on 03/05/10


event button Value dictionary as3 store proxy utils joey lott

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


AS3 Use Dictionary Obect to Store Values Associated with MovieClips

 / Published in: ActionScript 3

To do this sort of thing (ie. passing values to an onRelease event handler) in AS2 I would have used Joey Lott's Proxy class, which was similar to Delegate. To do this in AS3 you could create your own custom class which extends MovieClip and then store the value as a property which can then be retrieved in the event handler, but sometime just using a Dictionary Object is easier and quicker.

  1. // This example assumes there are 10 movieClips on stage named btn1, btn2, btn3 ... etc
  3. import flash.utils.Dictionary;
  5. var btnDict:Dictionary = new Dictionary();
  7. for (var i:uint=1; i<=10; i++) {
  8. var tempBtn:MovieClip = this["btn"+i];
  9. tempBtn.addEventListener(MouseEvent.CLICK, onBtn_CLICK);
  10. tempBtn.buttonMode = true;
  11. tempBtn.mouseChildren = false;
  12. btnDict[tempBtn] = i;
  13. }
  15. function onBtn_CLICK(event:MouseEvent):void {
  16. trace(btnDict[]);
  17. }

Report this snippet  

You need to login to post a comment.