---
title: "ActionScript项目条件编译"
author: "cuixuxucui"
date: "2011-06-24T17:28:50Z"
tags: []
categories: ["Web前端"]
slug: "actionscript"
draft: false
lastmod: "2011-06-24T17:28:50Z"
id: 1104298
url: "https://smartblack.iteye.com/blog/1104298"
---

我们可能需要一些配置常量，来决定代码实际运行时要走哪一段逻辑。

但如果仅仅是些测试逻辑，那就不必要编译进主SWF中了，比如一些Trace信息或假数据。

最好的办法是走独立的单元测试，也可以偷懒用条件编译。这可能会让项目代码有些乱糟糟，所以我不是很推荐。

参考：[通过条件编译来清洁你的ActionScript代码](http://bbs.9ria.com/viewthread.php?tid=38515&extra=&page=1)

比如代码：

private function test():void{

var repeat:int = 5;

CONFIG::DEBUGGING{

trace("debug"+repeat);

}

}

一、在FlashDevelop中很方便设置：

Project Properties-&gt;Compiler Options-&gt;Additional Compiler Options-&gt;

Enter the strings in the collection (one per line):表示更多的编译参数需要换行另写

-define=CONFIG::DEBUGGING,true

 

二、在flash builder中设置：

项目-&gt;属性-&gt;ActionScript编译器-&gt;附加的编译器参数：

-locale zh\_CN -define=CONFIG::DEBUGGING,false

注意：更多的编译参数用空格隔开