Using Config Constants to toggle implementations
December 22nd, 2010Our product relies on a “SWF to EXE” solution to give it drag, document CRUD and other “Desktop” functionality.
The two products contending are MDM Zinc and Screentime mProjector, both have their Pros and Cons but both essentially do whats needed.
But we are not resolved on either of them yet and need to toggle them as we progress.
This is where Config Constants lends a hand. By setting these compiler constants in your IDE or ANT builds you can toggle what gets compiled:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | private var _iDesktopS:IDesktopService; private var _iDragS:IDragService; private function configure():void { LIBRARY::MDM { _iDesktopS = new MDMDesktopService(); _iDragS = new MDMDragService(); } LIBRARY::MPROJECTOR { _iDesktopS = new MProjectorDesktopService(); _iDragS = new MProjectorDragService(); } _iDesktopS.setup(this); _iDragS.setup(this); } private function handleCloseRequest(e:MouseEvent):void { _iDesktopS.close(); } |
Using config constants that you define in the publish settings, you can specify whether certain lines of ActionScript code are compiled or not.
Setup is done easily in Flash:
Or you can implement it in your ANT build:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <target name="communicator"> <mxmlc file="${SRC_DIR}\coza\d6technology\communicator\communicator.mxml" output="${BIN_DIR}\communicator.swf" load-externs="${BASE_DIR}\shellLinkReport.xml" link-report="${BASE_DIR}\communicatorLinkReport.xml" debug="${DEBUG}" default-frame-rate="${FRAME_RATE}" optimize="true" static-rsls="true"> <define name="LIBRARY::MDM" value="false"/> <define name="LIBRARY::MPROJECTOR" value="true"/> <keep-as3-metadata name="Inject" /> ........ |
You are not just restricted to boolean values, although i haven’t tested this, but you can match the constant to a value as shown here: http://www.ericd.net/2009/01/config-constants-in-flash-cs4.html





