...
JS-only or SWF-only Components
Code Block |
---|
import org.apache.flex.utils.EffectTimer; EffectTimer;
import org.apache.flex.utils.MixinManager; MixinManager;
COMPILE::AS3
{
import org.apache.flex.utils.PNGEncoder; PNGEncoder;
import org.apache.flex.utils.SolidBorderUtil; SolidBorderUtil;
import org.apache.flex.utils.StringTrimmer; StringTrimmer;
}
import org.apache.flex.utils.Timer; Timer;
import org.apache.flex.utils.CSSUtils; CSSUtils;
COMPILE::JS
{
import org.apache.flex.utils.Language; Language;
}
|
In this snippet you can see that PNGEncoder, SolidBorderUtil and StringTrimmer are only needed for SWF versions, and org.apache.flex.utils.Language is only used in JS versions.
Build-related Files
There are several files involved in building the SWC. The goal is to cross-compile the JS version, then compile the SWF version and create a SWC that includes the .JS files from the cross-compile.
The build.xml file for a SWC should have 3 main steps:
- compile-asjs: This cross-compiles the JS version using the js.swc from Falcon (as opposed to playerglobal.swc or airglobal.swc) for the "built-in" classes (Object, Array, String, Number, etc). The COMPILE::AS3 flag should be false and the COMPILE::JS flag should be true.
- compile-extern-swc: This compiles a SWF for a SWC but still using the js.swc from Falcon. This SWC is placed in an externs folder for use as a dependent SWC by downstream SWCs. This SWC is needed so that only the API surfaces exposed by COMPILE::JS are available to consumers of this SWC. Application developers should never need to access these SWCs, only downstream SWC developers.
- compile: This is the final phase that compiles a SWF for a SWC with COMPILE::AS3 true and COMPILE::JS false and using playergloba.swcl or airglobal.swc for the built-in classes.
The list of files that are compiled by each phase is controlled by a compile-asjs-config.xml file for steps 1 and 2, and compile-config.xml for step 3.
The compile-asjs-config.xml file
- Should have an empty external-library-path entry. The external-library-path is specified in build.xml so we can use Ant to resolve the reference to js.swc in the Falcon repo
- Should use upstream SWCs from the externs folder, not the libs folder (so that the API surfaces are the ones exposed by COMPILE::JS
The compile-config.xml file
- Should have playerglobal.swc or airglobal.swc as the external-library-path entry
- Should use upstream SWCs from the libs folder and not the externs folder
- Should have "include-file" entries for the js/out folder
Code Block |
---|
<include-file>
<name>js/out/*</name>
<path>js/out/*</path>
</include-file> |
The build.xml not only includes the JS files in the SWC, but also copies them to frameworks/js/FlexJS/libs. The FalconJX compiler is told to look at frameworks/js/FlexJS/libs first, then look in the SWCs. This is done to enable folks to monkey-patch JS files in frameworks/js/FlexJS/libs and not have to rebuild a SWC. The danger is that a stale file in frameworks/js/FlexJS/libs can override your changes that went into the SWC.