小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

ClassFactory实例.

FLEX的例子中经常看到这个类.来个实例看看如何应用。

package
{
    import flash.display.Graphics;
 
    import mx.core.UIComponent;
 
    public class Square extends UIComponent
    {
        public var color:uint=0xFFFFFF;
        public function Square()
        {
            super();
        }
        protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth,unscaledHeight);
            var g:Graphics = graphics;
            g.clear();
            g.beginFill(color);
            g.drawRect(0,0,100,100);
            g.endFill();
        }
 
 
 
    }
}

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()"
     layout
="horizontal">
    
<mx:Script>
        
<![CDATA[
 
            private var myClassFactory:ClassFactory = new ClassFactory(Square);
            private function initApp():void
            {
                var whiteSquare:Square = myClassFactory.newInstance();
                myClassFactory.properties={color:0x000000};
                var blackSquare:Square = myClassFactory.newInstance();
                myClassFactory.properties={color:0xFF0000};
                var redSquare:Square = myClassFactory.newInstance();
                addChild(whiteSquare);
                addChild(blackSquare);
                addChild(redSquare);
            }
        
]]>
    
</mx:Script>
 
 
 
</mx:Application>

来自:http://sherifabdou.com/2008/06/05/example-of-using-the-classfactory-class/

posted on 2008-06-12 18:47  『小小菜鸟』  阅读(1611)  评论(0编辑  收藏  举报