flash on 2013-2-13

by TmskSt
♥0 | Line 66 | Modified 2013-05-26 14:33:57 | MIT License
play

ActionScript3 source code

/**
 * Copyright TmskSt ( http://wonderfl.net/user/TmskSt )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lXDm
 */

package {
    import flash.display.Sprite;
    import com.actionscriptbible.Example
    public class FlashTest extends Example {
        
        public function FlashTest() {
            // write as3 code here..
            
            const container_A:Container = addChild(new Container(0xFF0000)) as Container;
            this.addChild(container_A);
            container_A.y = 100;
            
            const container_B:Container = addChild(new Container(0x00FF00)) as Container;
            this.addChild(container_B);
            container_B.x = 100;
            container_B.y = 100;
            
            const container_C:Container = addChild(new Container(0xFF00FF)) as Container;
            this.addChild(container_C)
            container_C.x = 200;
            container_C.y = 100;
            
            var gfx_a:GFX = new GFX();
            gfx_a.y = 50;
            container_A.addChild(gfx_a);
            
            var both:GFX = new GFX();
            container_A.addChild(both);
            container_B.addChild(both);
            
            var remove:GFX = new GFX();
            remove.y = 100;
            container_C.addChild(remove);
            container_C.removeChild(remove);
            
            trace("container_A.numChildren", container_A.numChildren);
            trace("container_B.numChildren", container_B.numChildren);
            trace("container_C.numChildren", container_C.numChildren);
            
        }

    }
}

import flash.display.*;
import flash.text.*;
class TestDisplayObjectContainer extends Sprite {
    
    private var tf:TextField = new TextField();
    public function TestDisplayObjectContainer() {
        super(); 
        this.addChild(tf);
        tf.appendText("constructor\n");
        
    }
    
    public override function addChild(child:DisplayObject):DisplayObject {
        tf.appendText("addChild\n");
        return super.addChild(child);
    }
    
    public override function removeChild(child:DisplayObject):DisplayObject {
        tf.appendText("removeChild\n");
        return super.removeChild(child);
    }
    
    public override function removeChildAt(index:int):DisplayObject {
        tf.appendText("removeChildAt\n");
        return super.removeChildAt(index);
    }

}

class GFX extends Shape {
    public function GFX() {
        graphics.beginFill(0xFFFFFF * Math.random());
        graphics.drawCircle(0, 0, 10);
    }

}

class Container extends TestDisplayObjectContainer{
    public function Container(color:uint) {
        graphics.beginFill(color);
        graphics.drawRect(0, 0, 100, 100);
    }

}