For a recent project I had the need for an as3-only swf to ‘preload itself’. See this post.
I solved it, but during that project I reoccurring but unsolved problem arose. How can I create a custom Flash Builder Compiler argument. I googled around and posted on twitter and emailed some colleagues. I found nothing. Perhaps I didn’t know how to ask the question properly (sometimes that happens with coding questions).
Recently I found the solution on another post here. Very cool.
I created a quick demo which summarizes my findings and posted below. But here is the 2-step gist.
1. Set Compiler Argument
Wherever you configure mxmlc (Project properties of Flash Builder or FDT or other Eclipse-based-tool or command-line, set a custom compiler argument.
2. Use the Compiler Argument
Then anywhere in your AS3 you can access this variable.
[actionscript3 light=”true”]trace ("FOO::Bar: " + FOO::bar); //this will show ’27′[/actionscript3]
Alternatively you could use an external configuration file to do this. In my needs I needed access to this on ‘line #1’ of my code. I didn’t have time to wait for a configuration file to load and be parsed.
You could also create a class that returns values of
for you. You can have something like
return that for you. This way you don’t have to spread the odd ‘::’ syntax around your code, and you can more easily change the compiler argument syntax with minimal AS3 changes.
- Download the sourcecode (See ‘Member Resources’ below) for a simple example.
[private_Free member]Enjoy this members-only content!