This is a continuation of
Building FLEX Integration with SHP - please refer to it for refresher.
The next step of the integration is to do FLEX development directly within SHP. If you are used to develop FLEX apps in IDE such as Flex Builder, you might not necessary need this capability. But consider the following:
- potential for modularizing the flex scripts
- potential for graceful degradations into ajax or pure html
- possibility for automating the generation of simple flex-based solutions
All of which are powerful building blocks for web development, so we'll give it a shot. Let's get started.
Goal
We want to be able to write in MXML and ActionScripts in SHP, and have the script being compiled in real-time into the flash movie and served to browser transparently.
Example:
Here's a mxml shp script for hello world:
(mx:app (mx:script "private function clickHandler(evt:Event):void {
messageDisplay.text = \"I am Glad, it does.\";
}")
(mx:label "Flex without Flex Builder")
(mx:button #:label "Yes, It Works!" #:click "clickHandler(event)")
(mx:label #:id "messageDisplay"))
Which should be compiled into the following mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private function clickHanlder(evt:Event):void {
messageDisplay.text = "I am Glad, it does.";
}
]]>
</mx:Script>
<mx:Label text="Flex without Flex Builder" />
<mx:Button label="Yes, It Works!" click="clickHanlder(event)" />
<mx:Label id="messageDisplay" />
</mx:Application>
And then compiled into a flash video file, and finally served to the client
via the (flash) inclusion. And we should check the timestamp of the SHP script against the compile flash video so we won't waste CPU cycle by compiling the same script over and over again.
The first thing to do is to ensure we can generate the correct MXML. It is mostly straight forward:
(define (mx:app . widgets)
`(mx:Application ((xmlns:mx "http://www.adobe.com/2006/mxml"))
. ,widgets))
(define (mx:label (text "") #:id (id #f))
`(mx:Label ((text ,text)
,@(if (not id) '() `((id ,id))))))
(define (mx:button #:label (label "") #:click (click #f))
`(mx:Button ((label ,label)
,@(if (not click) '() `((click ,click))))))
;; more mxml widget definitions
With the above we now can generate the MXML, albeit in an incomplete form. The next step would then be to get the generated mxml *saved* to a predefined location, instead of serving them.