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

Vectorのunshiftがおかしい

数値以外を入れるとunshiftがバグる
レイアウトが崩れるので undefined は X と表示している
追記:Version 10,0,22,87 では修正されているようです
Get Adobe Flash player
by ton 14 Apr 2009
//数値以外を入れるとunshiftがバグる
//レイアウトが崩れるので undefined は X と表示している

//追記:Version 10,0,22,87 では修正されているようです
package{
    import flash.display.Sprite;
    import flash.text.TextField;
    public class VectorTest extends Sprite {
        private const N:int = 5;
        private var tf:TextField = new TextField();
        
        private var a1:Array = new Array();
        private var a2:Array = new Array();
        private var a3:Array = new Array();
        private var a4:Array = new Array();
        private var a5:Array = new Array();
        private var a6:Array = new Array();
        
        private var v1:Vector.<int> = new Vector.<int>();
        private var v2:Vector.<Number> = new Vector.<Number>();
        private var v3:Vector.<Boolean> = new Vector.<Boolean>();
        private var v4:Vector.<String> = new Vector.<String>();
        private var v5:Vector.<A> = new Vector.<A>();
        private var v6:Vector.<Object> = new Vector.<Object>();
        
        public function VectorTest() {
            tf.autoSize = "left";
            addChild(tf);
            
            append("array", "int","n", "boo", "str", "A", "obj");
            append("length", a1.length, a2.length, a3.length, a4.length, a5.length, a6.length);
            for (var i:uint = 0; i < N; i++) {
                append("length:", a1.unshift(i), a2.unshift(i), a3.unshift(true), a4.unshift(i.toString()), a5.unshift(new A(i)), a6.unshift(new Object().id = i));
            }
            append("");
            for (i = 0; i < N; i++) {
                append("element", a1.shift(), a2.shift(), a3.shift(), a4.shift(), a5.shift(), a6.shift());
            }
			
			
            append("--------------------------------------------------------------------------------------------------------");
            
			
			append("vector", "int","n", "boo", "str", "A", "obj");
                        append("length", v1.length, v2.length, v3.length, v4.length, v5.length, v6.length);
            for (i = 0; i < N; i++) {
                append("length:", v1.unshift(i), v2.unshift(i), v3.unshift(true), v4.unshift(i.toString()), v5.unshift(new A(i)), v6.unshift(new Object().id = i));
            }
            append("");
            for (i = 0; i < N; i++) {
                append("element", v1.shift(), v2.shift(), v3.shift(), v4.shift(), v5.shift(), v6.shift());
            }            
        }
        
        private function append(... args):void {
            for (var i:int = 0; i < args.length; i++) {
                tf.appendText(args[i] === undefined ? "X" : args[i])
                	tf.appendText("\t\t\t");
            	}
            	tf.appendText("\n");
        	}
    }
}

class A {
    	private var id:int;
    	public function A(id:int) {
       	this.id = id;
    }
    	public function toString():String {
        	return id.toString();
    	}
}