Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A FlexJS SWC is intended to be an compressed archive of not only pre-compiled ActionScript code and related assets, but also for a collection of JavaScript files that mirror the ActionScript classes in the SWC.  That way, a SWC can be deployed and used in a project without having to also copy around a pile of JS files.

The recommended order of operation steps for creating a SWC is:

1) Cross-compile the AS to JSCreate a Flex Library project

2) (OptionalOptionally) Create an Externs SWC.  An Externs a "JS" Flex Library project to produce a "JS" SWC.  A "JS" SWC is needed so that if APIs only available in the JS runtime are available to SWCs that depend on the SWC other SWCs and any runtime-specific code you are creating.

3) Compile the AS into a SWC and use include-files to include the cross-compiled JS output.

 

When you edit and save changes to AS files in the project, the cross-compiler will generate the JS files and include them in the SWC.  If you have created a "JS" Flex Library project, the compiler will also update the "JS" SWC.

Most, if not all, of the FlexJS framework SWCs use two Flex Library projects to produce a SWC with Flash-specific APIs and another with JS-specific APIs.  The APIs in common are the ones the application developer can use to write code that will work on both runtimesThere doesn't appear to be a way to easily do the three steps from a single Flex Library project in Adobe Flash Builder, unless you also add an Ant Builder to the project.  Some folks use two Flex Library projects instead.

 

The FlexJS framework uses Ant scripts to create the SWCSWCs.  In each folder in frameworks/projects, you should find  For each SWC, like Core, there should be:

a) build.xml - the Ant script (in frameworks/projects/Core, and another one in frameworks/js/FlexJS/projects/Core)

b) (in frameworks/js/FlexJS/projects/Core) src/main/resources/compile-asjsjs-config.xml  - Settings used to cross-compile AS to JS and also to create the Externs for the "JS" SWC

c) (in frameworks/projects/Core) src/main/resources/compile-as-config.xml - Settings used to compile the AS to SWF byte code and package include the cross-compiled JS output files into the  from the "JS" SWC.

 

The Ant script performs the 3 steps of the order of operation, but also copies the JS files to frameworks/js/FlexJS/libs.  When an application is being compiled and JS files are finally need to be linked into the cross-compiled output, the FalconJX compiler looks there before it looks in the SWC for a JS file that matches an AS class.  This allows developers to monkey-patch and quickly try changes to the JS without having to re-build the entire SWC.

In More Detail

When compiling the Flash-specific SWCWhen compiling in step 1 and 2, the COMPILE::AS3 SWF conditional compilation flag is set to false and COMPILE:JS is true.  Only on the last step 3 is COMPILE::AS3  When cross-compiling AS to JS,  COMPILE::SWF set to true and COMPILE::JS set to false.

In More Detail
The "SWF" SWC and "JS" SWC have different library dependencies.  At the "bottom" is the runtime SWC.  The "SWF" SWC has an external library path that includes playerglobal.

...

swc.  The "JS" SWC has an external library path that includes js/libs/js.swc.  Playerglobal.swc includes APIs for Flash like Sprite, the js.swc includes APIs for JS like HTMLElement.
The "JS" SWC has a library path that references other "JS" SWCs, like CoreJS.swc, and the "SWF" SWC has a library path that references other "SWF" SWCs like Core.swc.
Base Classes and other classes are then written against Flash APIs for SWF or JS APIs for JS.  UIBase, for instance, extends Sprite for Flash but extends Object and wraps an HTMLElement for JS.  Conditional Compilation is used where needed.

...