In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ObjectとDictionaryの動作比較テスト

Get Adobe Flash player
by tepe 31 Jan 2012
    Embed
/**
 * Copyright tepe ( http://wonderfl.net/user/tepe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/83yq
 */

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.utils.Dictionary;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..

            var dictionary:Dictionary;
            dictionary = new Dictionary(true);

            var object:Object;
            var t:TextField = new TextField();
            t.y = 100;
            t.text = "aa2";
            addChild(t);
            object = new Object();
            for (var n:uint = 0; n < 3; n++) {
                var btn:Sprite = new Sprite();
                btn.graphics.beginFill(0xff0000);
                btn.graphics.drawRect(n*100,0,50,50);
                btn.graphics.endFill();
                addChild(btn);
    
                btn.addEventListener(MouseEvent.CLICK, click);
                object[btn] = n;
                dictionary[btn] = n;
            }
            function click(evt:MouseEvent):void {
                //trace(object[evt.target]);
                t.text = "obj : "+object[evt.target]
                t.appendText("\ndictionary : "+ dictionary[evt.target]);
            }
            
        }
    }
}