Ted Patrick - Demos & MAX @ Adobe Systems


Note: This is the personal blog of Ted Patrick. The opinions and statements voiced here are my own.



How to use Flex with and without a server

DIGG IT!     11 Comments Published Thursday, June 02, 2005 at 5:51 AM .

I like to develop with the Flex server and deploy to static SWF. Flex MXML uses URLRewriting to mask compiler operations, flash detection, caching, and to provide a seamless URL to the app. Lets use this fact to our advantage.&

By default an MXML document returns HTML. When the browser receives the HTML, it calls the MXML URL slightly differently to obtain the SWF and JS needed to make Flex apps work seamlessly. The URL base remains the path to the MXML document but the content returned is different per request.

Here is the secret:
To obtain a SWF file from an MXML document, just add ".swf" to the URL.

Returns HTML:
http://localhost:8700/flex/myapp/index.mxml


Returns SWF:
http://localhost:8700/flex/myapp/index.mxml.swf


That was tough. Now lest use a simple script to call this URL and use it to obtain a SWF locally. I love Python and have written many utility files for working with SWF to speed my compilation and deployment. Some compile all MXML in a directory, some download SWF from Flex and FTP it to the production server.

Here is the base script for downloading the Flex generated SWF file.

import urllib

urllib.urlretrieve( "http://localhost:8700/flex/myapp/index.mxml.swf" , "index.swf" )


Wow, 2 lines of code, it's a miracle. This is simple so that I can do this 1000 times without making a mistake. Its precise and works on WIN/LIN/OSX/BSD or anywhere Python works. You can run this on the server to update files remotely.

Lets extend this a bit. I work over a VPN so I have local mapping to the servers. This is my deployment script for deploying a Flex SWF.

import urllib, shutil

urllib.urlretrieve( "http://localhost:8700/flex/myapp/index.mxml.swf" , "index.swf" )

shutil.copyfile( "index.swf" , "X:\\myapp\\index.swf" )


This one will download the SWF, then copy the file to a server path.

The benefits of doing this are that many developers can share one Flex server for development. In the ANT script that Darron highlighted, it has 71 lines of fairly complex ANT config code. He is doing more like supporting RSLs but you only need to add one line the the above script to add that. I simply question using ANT in regards to its complexity not capability. I prefer simple tools that are reliable, understandable, and very reusable. To each his own.

The Flex server is of great benefit. The services within Flex provide a multitude of important integration benefits that are essential to larger companies. For me, I do not use them and most likely won't but many will do great things with them. You can remote directly with Java from Flex and provide added security to Web Services via server configuration.

There are many ways to use Flex and Flash, none of them are wrong, they are just different. Each developer sees problems differently based on expensive, the problem at hand or the infrastructure/services available to them. There are 1000's of ways to make things work, to each his own.

Cheers,

ted ;)

11 Responses to “How to use Flex with and without a server”

  1. # Anonymous darron

    Thanks for sharing your solution, but it still requires the Flex server to be running. This is not an option in my case, which is why I came to build my ant script.

    Lines of code does not necessarily equal complexity. I'm very comfortable with ant, and it integrates into my workflow. I use Eclipse to build my .mxml files, so I simple click the "run" button and the ant build kicks off and builds whatever it was I was working on, showing my all of the warnings / errors in the Eclipse console window.

    As they say, different strokes for different folks, but I'll stand by my ant solutuion because it seemslessly integrates with my workflow, even if it's more "verbose". :-)

    The more options available, the better for everyone.  

  2. # Anonymous JesterXL

    Ant, Python... I don't care, I just want a SWF!  

  3. # Anonymous kai

    Hi guys,

    This is good stuff, but the Flex EULA does not allow to run Flex apps without the Flex server. At least that is what I have heard.

    I blogged about this same thing a while ago at http://www.beamjive.com/lounge/index.php?a=1&id=44

    Let's just hope that the next Flash version ships with a command line mxml compiler :)  

  4. # Blogger Ted Patrick

    Kai,

    You need to have a CPU License everywhere Flex SWF is deployed. That is the golden rule.

    In this case, I am using one CPU License for my BSD/Apache HTTP Server where Flex or Java is NOT running. This is strictly for deployment. I use another CPU for development.

    For more detail talk to your Macromedia Rep.

    Ted ;)  

  5. # Anonymous Kenny Bunch

    Interesting note on your deployment strategy. Are you saying you don't deploy your swfs on client's servers. You actually put the swfs on your servers and have them reference it? That way you are only paying for your CPU and your clients dont have to eat the cost of Flex?  

  6. # Blogger Ted Patrick

    Kenny,

    Your statements are incorrect.

    1. All my clients license Flex.

    2. We deploy static SWF to a server with a Flex CPU License.

    3. The new company I am involved in licensed Flex.

    4. We deloy SWF to a server with a Flex CPU License.

    What you have proposed is a clear violation of the Flex EULA.

    Ted ;)  

  7. # Anonymous Kenny Bunch

    Gotcha, I hadn't read the EULA yet.  

  8. # Anonymous Docs

    It is not clear from Adobe website as to when we need a Flex Server (Flex Data Services) and when we dont. IN some places they say that we can have a Flex application running without FDS and in some other place they contradict this by saying that we need to buy a FDS license to run any Flex app.

    Currently we have a application developed using Flex Builder, converted into a SWF and is being deployed on the CLient (installed on the client PC). This SWF file then connects to a JBoss server on runtime to get data back and forth. We configure a Remoting-config.XML file deployed inside the App server.

    It is even more confusing because we did not install FDS, but there are some SWC files on the server that look like FDS components. We are not sure what FDS carries. Adobe says that remote-objects require FDS, but in another place in thier website they say that RPC is one way to communicate from a client to server (even without FDS) and remote-object is one method of communication within RPC. So, do we need FDS (Flex Server)?

    Thanks !  

  9. # Anonymous Docs

    It is not clear from Adobe website as to when we need a Flex Server (Flex Data Services) and when we dont. IN some places they say that we can have a Flex application running without FDS and in some other place they contradict this by saying that we need to buy a FDS license to run any Flex app.

    Currently we have a application developed using Flex Builder, converted into a SWF and is being deployed on the CLient (installed on the client PC). This SWF file then connects to a JBoss server on runtime to get data back and forth. We configure a Remoting-config.XML file deployed inside the App server.

    It is even more confusing because we did not install FDS, but there are some SWC files on the server that look like FDS components. We are not sure what FDS carries. Adobe says that remote-objects require FDS, but in another place in thier website they say that RPC is one way to communicate from a client to server (even without FDS) and remote-object is one method of communication within RPC. So, do we need FDS (Flex Server)?

    Thanks !  

  10. # Blogger photo blogger

    Glad we don't have to this any more... Thanks anyway though.  

  11. # Anonymous Embed

    The joys of software licensing. Why can't everything be open?  

Post a Comment

Where to find me:

Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe


Latest

Lists

Links

Jobs

Flex Jobs
city, state, zip

Archives