You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

History

  • 1/11/2013 - MXML-based project can now be compiled into a working HTML/JS project

Set Up

  1. Get Apache Flex 4.9 up and running. We don't really use any of its code, but getting it up and running makes sure you have the build tools and playerglobal.swc we need.
  2. Get the ASJS code from: https://svn.apache.org/repos/asf/flex/asjs/branches/develop/
  3. In the frameworks/as folder, run ant. You may need a local.properties or a FLEX_HOME environment variable to build successfully. This should result in a frameworks/as/libs/FlexJSUI.swc
  4. Get the Falcon code from https://svn.apache.org/repos/asf/flex/falcon/trunk/
  5. Run ant to build Falcon.
  6. Change to compiler.js folder and run ant to build FalconJS.

The Demo

MXML->SWF
In the ASJS folders under branches/develop/examples/FlexJSTest_again is a sample "hello world" application. You should be able to compile FlexJSTest.mxml into a working SWF by using Falcon (and not the MXMLC compiler in Apache Flex 4.9). Find the Falcon mxmlc script in the Falcon folders under compiler/generated/dist/sdk/bin and run:

mxmlc -compiler.mxml.children-as-data -library-path+=<path to folder containing FlexJSUI.swc> FlexJSTest.mxml

You should be able to launch the SWF, see a button and some text, click the button and see the text change.

MXML->JS
Now you should be able to create an HTML/JS equivalent by running FalconJS. In compiler.js/bin is its mxmlc script. Use the exact same arguments as you did before, i.e.

mxmlc -compiler.mxml.children-as-data -library-path+=<path to folder containing FlexJSUI.swc> FlexJSTest.mxml

and the FalconJS compiler will (currently) generate a bunch of .js files, one for each .mxml and .as file. These files go along with the Google Closure Library's base.js and an HTML file to create a rough equivalent to the SWF. Someday, FalconJS will output a single minified .js file instead of all of these files. But for now, you can use the Google Closure tools and scripts to combine all of the .js files into a single minified .js file. In the ASJS folders under branches/develop/publisher is an attempt to create a build script that does all of these things. If you can't get it all to work, or you want to see the code un-minified, you can create an html file that looks something like this:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="goog/base.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/flash/events/Event.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/FlexGlobal.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/FlexObject.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/utils/MXMLDataInterpreter.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/UIBase.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/ViewBase.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/Label.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/binding/SimpleBinding.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/TextButton.js"></script>
<script type="text/javascript" src="examples/FlexJSTest_again/MyInitialView.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/ValuesManager.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/SimpleValuesImpl.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/Application.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/core/IDocument.js"></script>
<script type="text/javascript" src="examples/FlexJSTest_again/MyController.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/TextFieldBead.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/TextButtonBead.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/models/TextModel.js"></script>
<script type="text/javascript" src="examples/FlexJSTest_again/MySimpleValuesImpl.js"></script>
<script type="text/javascript" src="frameworks/js/FlexJS/src/flash/events/EventDispatcher.js"></script>
<script type="text/javascript" src="examples/FlexJSTest_again/MyModel.js"></script>
<script type="text/javascript" src="examples/FlexJSTest_again/FlexJSTest.js"></script>
<script type="text/javascript">
	var app = new FlexJSTest();
</script>
<title>FlexJSTest</title>
</head>

<body onload="app.start()">
</body>
</html>

If you then open the HTML file in a browser (I've only been using FireFox on Mac) you will again see the button and text and clicking on the button will change the text but hey! no Flash is involved. It is pure HTML/JS. Right now the appearance of things is a bit different, but that is a To Do item. I don't know if we can make it exactly the same as it looks in Flash, but we should be able to get better visual match.

MXML->Cordova/PhoneGap

Once you have the HTML and JS file(s), you can copy these into the www folder in a Cordova/PhoneGap application and publish it and see it work on a phone or desktop emulator. A To Do item is to automate this process.

Notes

  • The code does not currently support the classic {} data-binding syntax. Instead, you can install a "beads" plug-in to handle simple binding scenarios. See the use of SimpleBinding in MyInitialView.MXML.

Discussion

As you can hopefully see, the first building blocks are now in place such that the ASJS framework and FalconJS compiler can create applications using familiar tools, components, and workflows. You can use Adobe Flash Builder or other Flex-capable IDE to quickly build or prototype an application on Flash using structured-programming techniques afforded by ActionScript, then convert it to a HTML/JS application that can run on browsers or mobile devices without Flash.

Next Steps

  • Fix "publisher" to generate minified js file and html file
  • More components
  • FalconJS option to output minified js file
  • FalconJS option to generate html file as well?
  • CSS handling for default values
  • Data-binding syntax support
  • No labels