/ 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.
Expand |
Embed | Plain Text
// This example assumes there are 10 movieClips on stage named btn1, btn2, btn3 ... etc import flash.utils.Dictionary; var btnDict:Dictionary = new Dictionary(); for (var i:uint=1; i<=10; i++) { var tempBtn:MovieClip = this["btn"+i]; tempBtn.addEventListener(MouseEvent.CLICK, onBtn_CLICK); tempBtn.buttonMode = true; tempBtn.mouseChildren = false; btnDict[tempBtn] = i; } function onBtn_CLICK(event:MouseEvent):void { trace(btnDict[event.target]); }
You need to login to post a comment.
