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.copy test

Get Adobe Flash player
by uwi 12 Jul 2009
    Embed
package {
    import flash.display.Sprite;
    import flash.text.*;
    import mx.utils.ObjectUtil;
    
    public class VectorCopyTest extends Sprite {
        public function VectorCopyTest() {
            var tf : TextField = new TextField();
            tf.height = 450;
            addChild(tf);
            
            var obj : Object;
            var o : Object;
            
            // Vector
            tf.appendText("VECTOR\n");
            var v : Vector.<A> = new Vector.<A>();
            v.push(new A("aa", 1));
            v.push(new A("bb", 2));
            
            obj = ObjectUtil.copy(v);
            
            tf.appendText((obj is Vector.<Object>) + "\n");
            tf.appendText((obj is Vector.<A>) + "\n");
            tf.appendText((obj[0] is A) + "\n");
            for each(o in obj){
                tf.appendText(ObjectUtil.toString(o) + "\n");
            }
            
            // Array
            tf.appendText("ARRAY\n");
            
            var a : Array = [];
            a.push(new A("aa", 1));
            a.push(new A("bb", 2));
            
            obj = ObjectUtil.copy(a);
            
            tf.appendText((obj is Array) + "\n");
            tf.appendText((obj[0] is A) + "\n");
            for each(o in obj){
                tf.appendText(ObjectUtil.toString(o) + "\n");
            }
            
            // Original
            tf.appendText("Original\n");
            
            var g : Array = [];
            g.push(new A("aa", 1));
            g.push(new A("bb", 2));
            
            for each(o in g){
                tf.appendText(ObjectUtil.toString(o) + "\n");
            }
        }
    }
}

internal class A
{
    public var a : String;
    public var b : int;
    
    public function A(a : String, b : int)
    {
        this.a = a;
        this.b = b;
    }
}