Flash-Injected Javascript does not Minify Properly in Ant

We’re using Flash to inject javascript onto our page, and to save space, we’re using a minifier to produce smaller javascript code. The issue is that we’re using a string replacement on our code and the minifier produces an odd result.

Consider the following code:

var id = myobj['ID_PLACEHOLDER'];

When we inject the code, we do a replace on ID_PLACEHOLDER and replace it with the appropriate ID. This is great, except that our minifier sees this as a waste of chars and minifies the system to:

var id = myobj.ID_PLACEHOLDER;

This would be well and good except that our IDs can begin with numbers and Javascript variables cannot. To solve this, I had to modify our placeholder to be:

var id = myobj['1_ID_PLACEHOLDER'];

This does not minify and produces correct code on the injected end.

Ant compc swc compile Error: ‘Class’ is undefined.

In making an Ant script to produce a swc of my project, I used the compiler.external-library-path to include an external swc. I forgot to include append=”true” and this killed the include of the needed flex swcs.

If you start getting lots of these errors that seem like the Flex/Flash basics aren’t compiling in, look for the swcs you’ve included and make sure you append them, not overwrite.

Here’s the errors I got, there’s a lot of them, but maybe this will help people find this information by searching:

    [compc] Error: 'flash.events:AsyncErrorEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:ByteArray' is undefined.
    [compc] 
    [compc] Error: 'encodeURI' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:escapeMultiByte' is undefined.
    [compc] 
    [compc] Error: 'EvalError' is undefined.
    [compc] 
    [compc] Error: 'flash.media:SoundTransform' is undefined.
    [compc] 
    [compc] Error: 'Array' is undefined.
    [compc] 
    [compc] Error: 'Math' is undefined.
    [compc] 
    [compc] Error: 'RegExp' is undefined.
    [compc] 
    [compc] Error: 'flash.ui:ContextMenuItem' is undefined.
    [compc] 
    [compc] Error: 'flash.system:ApplicationDomain' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextSnapshot' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:clearInterval' is undefined.
    [compc] 
    [compc] Error: 'flash.ui:ContextMenuBuiltInItems' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Scene' is undefined.
    [compc] 
    [compc] Error: 'flash.system:SecurityDomain' is undefined.
    [compc] 
    [compc] Error: 'flash.display:IBitmapDrawable' is undefined.
    [compc] 
    [compc] Error: 'Date' is undefined.
    [compc] 
    [compc] Error: 'flash.geom:Matrix' is undefined.
    [compc] 
    [compc] Error: 'flash.events:StatusEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:BlurFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.geom:ColorTransform' is undefined.
    [compc] 
    [compc] Error: 'isXMLName' is undefined.
    [compc] 
    [compc] Error: 'URIError' is undefined.
    [compc] 
    [compc] Error: 'flash.display:StageAlign' is undefined.
    [compc] 
    [compc] Error: 'ReferenceError' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:IllegalOperationError' is undefined.
    [compc] 
    [compc] Error: 'flash.text:FontStyle' is undefined.
    [compc] 
    [compc] Error: 'flash.net:URLStream' is undefined.
    [compc] 
    [compc] Error: 'flash.system:IMEConversionMode' is undefined.
    [compc] 
    [compc] Error: 'flash.net:navigateToURL' is undefined.
    [compc] 
    [compc] Error: 'XMLList' is undefined.
    [compc] 
    [compc] Error: 'flash.events:SecurityErrorEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.text:AntiAliasType' is undefined.
    [compc] 
    [compc] Error: 'flash.media:Microphone' is undefined.
    [compc] 
    [compc] Error: 'flash.net:registerClassAlias' is undefined.
    [compc] 
    [compc] Error: 'flash.net:getClassByAlias' is undefined.
    [compc] 
    [compc] Error: 'flash.events:ContextMenuEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.events:ProgressEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextField' is undefined.
    [compc] 
    [compc] Error: 'Class' is undefined.
    [compc] 
    [compc] Error: 'flash.ui:Mouse' is undefined.
    [compc] 
    [compc] Error: 'flash.display:DisplayObject' is undefined.
    [compc] 
    [compc] Error: 'flash.xml:XMLNodeType' is undefined.
    [compc] 
    [compc] Error: 'flash.net:NetStream' is undefined.
    [compc] 
    [compc] Error: 'isNaN' is undefined.
    [compc] 
    [compc] Error: 'flash.events:IMEEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:DropShadowFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.events:ActivityEvent' is undefined.
    [compc] 
    [compc] Error: 'decodeURIComponent' is undefined.
    [compc] 
    [compc] Error: 'adobe.utils:MMEndCommand' is undefined.
    [compc] 
    [compc] Error: 'flash.system:IME' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:setInterval' is undefined.
    [compc] 
    [compc] Error: 'flash.ui:Keyboard' is undefined.
    [compc] 
    [compc] Error: 'flash.events:Event' is undefined.
    [compc] 
    [compc] Error: 'flash.display:BitmapData' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:ScriptTimeoutError' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextFieldType' is undefined.
    [compc] 
    [compc] Error: 'decodeURI' is undefined.
    [compc] 
    [compc] Error: 'escape' is undefined.
    [compc] 
    [compc] Error: 'flash.display:GradientType' is undefined.
    [compc] 
    [compc] Error: 'flash.accessibility:AccessibilityImplementation' is undefined.
    [compc] 
    [compc] Error: 'flash.accessibility:AccessibilityProperties' is undefined.
    [compc] 
    [compc] Error: 'flash.media:Camera' is undefined.
    [compc] 
    [compc] Error: 'AS3' is undefined.
    [compc] 
    [compc] Error: 'flash.net:URLLoader' is undefined.
    [compc] 
    [compc] Error: 'Object' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:unescapeMultiByte' is undefined.
    [compc] 
    [compc] Error: 'flash.net:NetConnection' is undefined.
    [compc] 
    [compc] Error: 'flash.display:MovieClip' is undefined.
    [compc] 
    [compc] Error: 'flash.events:NetStatusEvent' is undefined.
    [compc] 
    [compc] Error: 'SecurityError' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:describeType' is undefined.
    [compc] 
    [compc] Error: 'UninitializedError' is undefined.
    [compc] 
    [compc] Error: 'flash.net:URLRequest' is undefined.
    [compc] 
    [compc] Error: 'Function' is undefined.
    [compc] 
    [compc] Error: 'DefinitionError' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:IDataOutput' is undefined.
    [compc] 
    [compc] Error: 'SyntaxError' is undefined.
    [compc] 
    [compc] Error: 'flash.events:IOErrorEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:IDataInput' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:setTimeout' is undefined.
    [compc] 
    [compc] Error: 'flash.display:SimpleButton' is undefined.
    [compc] 
    [compc] Error: 'Namespace' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:Timer' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:StackOverflowError' is undefined.
    [compc] 
    [compc] Error: 'flash.events:FocusEvent' is undefined.
    [compc] 
    [compc] Error: 'XML' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:flash_proxy' is undefined.
    [compc] 
    [compc] Error: 'VerifyError' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:GlowFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.net:URLVariables' is undefined.
    [compc] 
    [compc] Error: 'flash.display:DisplayObjectContainer' is undefined.
    [compc] 
    [compc] Error: 'flash.display:InteractiveObject' is undefined.
    [compc] 
    [compc] Error: 'flash.ui:ContextMenu' is undefined.
    [compc] 
    [compc] Error: 'flash.display:LoaderInfo' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:SetIntervalTimer' is undefined.
    [compc] 
    [compc] Error: 'flash.events:FullScreenEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Shape' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:BitmapFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextFormat' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Graphics' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:BevelFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.events:TimerEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.xml:XMLNode' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:IOError' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:MemoryError' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:IExternalizable' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Sprite' is undefined.
    [compc] 
    [compc] Error: 'flash.events:WeakFunctionClosure' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:InvalidSWFError' is undefined.
    [compc] 
    [compc] Error: 'flash.text:StyleSheet' is undefined.
    [compc] 
    [compc] Error: 'flash.events:IEventDispatcher' is undefined.
    [compc] 
    [compc] Error: 'flash.events:WeakMethodClosure' is undefined.
    [compc] 
    [compc] Error: 'NaN' is undefined.
    [compc] 
    [compc] Error: 'Number' is undefined.
    [compc] 
    [compc] Error: 'int' is undefined.
    [compc] 
    [compc] Error: 'flash.geom:Rectangle' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Loader' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:Proxy' is undefined.
    [compc] 
    [compc] Error: 'flash.geom:Point' is undefined.
    [compc] 
    [compc] Error: 'flash.net:Responder' is undefined.
    [compc] 
    [compc] Error: 'TypeError' is undefined.
    [compc] 
    [compc] Error: 'isFinite' is undefined.
    [compc] 
    [compc] Error: 'flash.events:MouseEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.text:Font' is undefined.
    [compc] 
    [compc] Error: 'String' is undefined.
    [compc] 
    [compc] Error: 'flash.errors:EOFError' is undefined.
    [compc] 
    [compc] Error: 'flash.system:Capabilities' is undefined.
    [compc] 
    [compc] Error: 'flash.display:Stage' is undefined.
    [compc] 
    [compc] Error: 'flash.system:LoaderContext' is undefined.
    [compc] 
    [compc] Error: 'parseFloat' is undefined.
    [compc] 
    [compc] Error: 'flash.geom:Transform' is undefined.
    [compc] 
    [compc] Error: 'parseInt' is undefined.
    [compc] 
    [compc] Error: 'ArgumentError' is undefined.
    [compc] 
    [compc] Error: 'flash.system:Security' is undefined.
    [compc] 
    [compc] Error: 'flash.events:KeyboardEvent' is undefined.
    [compc] 
    [compc] Error: 'QName' is undefined.
    [compc] 
    [compc] Error: 'encodeURIComponent' is undefined.
    [compc] 
    [compc] Error: 'flash.events:TextEvent' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:getQualifiedClassName' is undefined.
    [compc] 
    [compc] Error: 'flash.events:EventPhase' is undefined.
    [compc] 
    [compc] Error: 'undefined' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextFormatAlign' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextLineMetrics' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:getDefinitionByName' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:getQualifiedSuperclassName' is undefined.
    [compc] 
    [compc] Error: 'unescape' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:Dictionary' is undefined.
    [compc] 
    [compc] Error: 'flash.events:ErrorEvent' is undefined.
    [compc] 
    [compc] Error: 'adobe.utils:MMExecute' is undefined.
    [compc] 
    [compc] Error: 'flash.display:StageScaleMode' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextFieldAutoSize' is undefined.
    [compc] 
    [compc] Error: 'RangeError' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:clearTimeout' is undefined.
    [compc] 
    [compc] Error: 'trace' is undefined.
    [compc] 
    [compc] Error: 'flash.net:sendToURL' is undefined.
    [compc] 
    [compc] Error: 'flash.filters:ColorMatrixFilter' is undefined.
    [compc] 
    [compc] Error: 'flash.utils:getTimer' is undefined.
    [compc] 
    [compc] Error: 'Boolean' is undefined.
    [compc] 
    [compc] Error: 'flash.events:HTTPStatusEvent' is undefined.
    [compc] 
    [compc] Error: 'Error' is undefined.
    [compc] 
    [compc] Error: 'flash.events:EventDispatcher' is undefined.
    [compc] 
    [compc] Error: 'flash.external:ExternalInterface' is undefined.
    [compc] 
    [compc] Error: 'flash.text:TextRun' is undefined.
    [compc] 
    [compc] Error: 'Infinity' is undefined.
    [compc] 
    [compc] Error: 'flash.media:Video' is undefined.
    [compc] 
    [compc] Error: 'uint' is undefined.
    [compc] 

Building AS3 Using ANT Scripts

I spent a good chunk of time finding the simplest ANT build script I could and using it to compile my simple AS3 project. This is a simple as it gets:

<project name="build" default="compile">
	<property file="${ant.home}/path.properties"/>
	<taskdef resource="flexTasks.tasks" />
	<target name="compile">
		<mxmlc file="src/AntTest.as" output="bin-debug/AntTest.swf"/>
	</target>
</project>

The project name attribute is up to you.
The default is the target to be run if you just type “ant”
The first property sets basic ANT properties
The taskdef includes Flex-specific information
The target name allows you to reference this action elsewhere in the build file
The mxmlc file is the source for the compiler
The mxmlc output is the output for the compiler
Just replace the as file and swf file with your specific filenames, open up the terminal, browse to the project dir, and type ant
it should produce a swf for you.