Note that there are some explanatory texts on larger screens.

plurals
  1. POFlash, Ant and lots of regular expression replaces
    text
    copied!<p>I have a flash project which, for optimization purposes, has to have constant references replaced with literals during release build.</p> <p>There are hundreds of constants which I want to replace. All of them are stored in single file, in this format:</p> <pre><code>FILE: Constants.as public static const CONST_1 :uint = 0; public static const CONST_LOLO :int = -1; public static const CONST_WHEE :Number = 2.55; public static const OTHER_CONST :String = "La string!"; public static const ITSAMEMARIO :String = "O, HAI!"; public static const MAGE_WALL :uint = 15; </code></pre> <p>I figure I could do it manually, like that:</p> <pre><code>&lt;replaceregexp match="CONST_1" replace="0"&gt; &lt;fileset dir="${project.sourcePath}" includes="**/*.as" /&gt; &lt;/replaceregexp&gt; &lt;replaceregexp match="CONST_LOLO" replace="-1"&gt; &lt;fileset dir="${project.sourcePath}" includes="**/*.as" /&gt; &lt;/replaceregexp&gt; </code></pre> <p>And so on, for all the other variables. The problem is twofold - first of all, it is quite a lot of work. But the bigger problem is, that these constants can change and I'd have to remember to do the change in two places.</p> <p>Generally I am using Ant (which I just started to learn too) to accomplish this task, but if you think there is a better way, I am all ears. There are two solutions I can think of, none of which I know how to execute:</p> <ol> <li>Write some smarty-pants piece of Ant code which would parse this constants file and happily do the replaces keeping everything in memory.</li> <li>Make the task first parse the <em>Constants.as</em>, output a new Ant script, which then will be executed by the first task.</li> </ol> <p>I am using Flash Builder 4.5 for all my Ant needs.</p> <p>EDIT: Some clarification. In the project I am using Constants, for example LEVEL_WIDTH. All of these constants are declared in the aforementioned Constants.as. Now what I want is to replace all of the instances of these constants in the whole project with their actual value. So such line:</p> <pre><code>return (x &gt;= 0 &amp;&amp; x &lt; Constants.LEVEL_WIDTH); </code></pre> <p>will be replaced by:</p> <pre><code>return (x &gt;= 0 &amp;&amp; x &lt; 20); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload