views:

682

answers:

3

Greetings!

I am trying to build an application which has a flex front-end and a php back-end. I am struggling to do something with this application which I couldn't figure out a way to do. I would want my flex application to show a view based on an MXML it recieves from the server as a response to some interaction in the flex application. for example, lets say there are two buttons on the current view and if i press the first button, it will load one mxml/as3 from the server, and when i click the other, it will load a different mxml. How do you think i can tackle this situation ? Please shed some light if you know how to do this as i've been banging my head on the wall trying to figure out a way.

Best Regards,

Roshan Amadoru

+2  A: 

I think what you want to do is achieved by modules in Flex. You can't send MXML or .as to the flex application as it doesn't have a compiler to change them into binary executable code. So the way to do this is prepare separate application parts, which aren't downloaded with the main app but can be loaded to it later, called modules.

A blog post about flex modules: sujitreddyg.wordpress.com

If you don't want to compile modules before deploying them to the server but would rather put mxml code there (PHP style) you would need to install the Flex Module for Apache (the name module here is the same as flex modules by coincidence, it's an unrelated thing).

Robert Bak
+1  A: 

As Robert said, the Flash VM doesn't natively interpret as3 or mxml code, so you could go two ways :

  • If you need to dynamically generate code, you can try to use the Eval library (http://eval.hurlant.com/), which could fit your need.

  • If you already know the code you want to send, you can compile the different parts into swf or their own and link to the correct one depending on the outcome of previous events. (using modules). Most Flex frameworks will provide ways for you to do that.

Axelle Ziegler
Totally forgot about the As3 eval project, thanks.
Robert Bak
It's not completely straightforward to use, but it does it's job :)
Axelle Ziegler
A: 

Hi, in fact you can compile your mxml at runtime, but I don't know about performance. If your server side is java, granite (like in graniteDS) has a webcompiler servlet to compile your mxml in realtime. I've been using it while developing avoid compile it myself (plain eclipse EE, no flexbuilder) and seems to work just fine, minus two small issues I haven't taken the time to clarify:

1) if the servlet mapping is "/mxml/*" you'll need to access your mxml as

http://localhost://WebApp/mmxml/myUncompiled.mxml

See an extra 'm' in the path? don't know why...

2) can't compile code with or dropShadow or other filters, probably need changing something in servlet's flex-config.xml, wich is just like the xml configuration for mxmlc

Other than that, it seems to me this could be a pretty explosive mixture, .jsp and .mxml

j040p3d20