条件编译

很久之前看到过as3 在FB中的条件编译,今天突然想到,然后就在天地会转了点代码过来:

package
{
        import flash.display.Sprite;
        import flash.text.TextField;
       
        /**
         * 条件编译演示(在多版本控制中比较好用,比如下面指定的"中文版","日文版","英文版".在项目中也可以用来控制 web 版和 pad 版)
         * <p>编译后的代码量不会增加,因它是编译时进行处理的.<b>所谓的条件编译是指:<font color="#ff0000">根据指定的条件:选择性的编译其中的某一部分</font></b></p>
         * <p>需要在项目的编译选项中附加如下编译常量:</p>
         * <listing version="3.0">
         * -define=CONFIG::CHINESE,false
         * -define=CONFIG::JAPANESE,false
         * -define=CONFIG::ENGLISH,true
         * </listing>
         * 编译选项的设置:
         * <table>
         * <tr>
         *         <td>flash builder</td><td>选择要进行设置的项目 -> 右击 -> 选择"属性" -> 选择"ActionScript编译器" -> "附加的编译器参数"中指定</td>
         * </tr>
         * <tr>
         * <td colspan="2">其它的参见:<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html">http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html</a></td>
         * </tr>
         * @author blank
         *
         */
        public class conditionCompile extends Sprite
        {
                /**
                 * 名字
                 * @return
                 *
                 */
                private function get pName():String{
                        CONFIG::CHINESE{
                                return "小明";
                        }
                        CONFIG::JAPANESE{
                                return "梅川库子";
                        }
                        CONFIG::ENGLISH{
                                return "鸡姆";
                        }
                }
               
                /**
                 * 国籍
                 * @return
                 */
                CONFIG::CHINESE{
                        private function get nationality():String{
                                return "中国"
                        }
                }
                CONFIG::JAPANESE{
                        private function get nationality():String{
                                return "日本"
                        }
                }
                CONFIG::ENGLISH{
                        private function get nationality():String{
                                return "英国"
                        }
                }
               
                public function conditionCompile()
                {
                        var txf:TextField=new TextField();
                        txf.text="名字:" + pName + "\n" +
                                "国籍:" + nationality;
                       
                        txf.width=txf.textWidth + 4;
                        txf.height=txf.textHeight + 4;
                        addChild(txf);
                }
        }
}

posted on 2014-03-26 17:59  L . W  阅读(228)  评论(0编辑  收藏  举报