tags:

views:

1040

answers:

4

Hi, Is it Possible to pass MXML it self as parameter(XML param) from external application and load in Flash Player dynamically to create page. For e.g

passing xml = <mx:canvas><mx:label text="hello" /></mx:canvas> to Flex and flex should create canvas with label control in it. Is there any example related to it.

Thanx

A: 

My initial guess is no, it would still be of type "XML", and there is no "eval" in Actionscript 3. I did a quick search and am going to have to say no, this is not possible.

I have however, done something similar in an app I created.

What I did was store in a database the object type, and some properties (x,y,width,height, etc). This data is returned from a remote object call and these objects are then created at runtime, which can get a similar effect you are trying to achieve.

For example:

var resultAC:ArrayCollection = event.result as ArrayCollection;
var tmpCanvas:Canvas;

    for(var i:int = 0; i < resultAC.length; i++)
    {
      if(resultAC.getItemAt(i).type == "Canvas")
      {
         tmpCanvas = new Canvas();
         tmpCanvas.x = resultAC.getItemAt(i).x;
         tmpCanvas.y = resultAC.getItemAt(i).y;
         ...
         parent.addChild(tmpCanvas);
      }
    }
Chris Klepeis
+3  A: 

MXML code needs to be compiled down to ActionScript before Flash Player can do anything with it. MXML is not interpreted by Flash Player at runtime.

cliff.meyers
+1  A: 

What you are wanting to do is not possible. Like brd6644 said, mxml is compiled down to bytecode in the swf which is interpreted by the flash player. The mxml (and even actionscript) is not understood by the flash player.

That being said, there is a JSP library that you can use for dynamic MXML. See here:

http://www.adobe.com/devnet/flex/articles/server_perf_05.html

That link is old, and right now I can't seem to find an updated link, but I know the project still exists. I believe it actually ships as part of ColdFusion still. It allows you to create dynamic mxml which gets JIT compiled at the request. It of course has a substantial performance hit because of it, but if you need dynamic MXML it is an option.

I will update this comment with a better link when I find it.

Ryan Guill
+1  A: 

Just store the properties of the component to a XML and put a className attribute so that if you load the XML you can have a function to set the attributes of the XML to the properties of your created component which will be determined in your className attribute

Treby