views:

151

answers:

3

What are the differences between flex mxml and as3.

A: 

MXML is a declarative language to define the user interface elements of your views in a Flex application. You can also declare some non-UI elements which exist and support the page, but for the most part it's just used for the UI elements.

AS3 is a programming languages that is used to add all the logic and functionality to your application.

The two are tied together through events and data binding.

Sam
A: 

see the mxml code is compiled into the actionscript code and then into bytecode which is then executed by the flash player

see what happen in actionscript is, you have to decide the parent and child, so it's get a bit complex, u have to code for each n everything,

e.g.,

Canvas can=new Canvas();
can.percentHeight=100;
can.percentWidth=100;
can.addChild(new Button);

but in case of mxml, u only need one tag

<Canvas height="100%" width="100%"><button></button></Canvas>

so it's get easier to work in mxml, but there r some limitations of the mxml, so sooner or later u have to use Actionscript, thats what we all do daily

i hope u got some idea tc havw a gr8 day

Ankur Sharma
I took the liberty to format your code - in future, just select the code and press Ctrl-K to format it.
Amarghosh
sir, u r most welcome, even i've bcum ur fan, u r terrific, all the time, ur answers are excellent, hav a gr8 time n all the best
Ankur Sharma
+5  A: 

MXML is an XML based mark-up language for conveniently defining user interfaces and data binding using Flex framework. MXML files can include ActionScript inside <mx:Script> tags - similar to how you can have javascript in an html file.

The Flex compiler converts MXML mark-up into ActionScript-3 code before compiling it to SWF/SWC. Most of the things that you do in MXML can also be done with ActionScript, but it'll take more lines of code to do it.

An mxml file creates an actionscript class of the same name that extends the class corresponding to the root tag of the mxml file. For example, the following code in MyCanvas.mxml generates MyCanvas class that extends the Flex Canvas class.

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="200"
   creationComplete="init(event)">

   <mx:Label text="{someVar}" id="theLabel"/>

   <mx:Script>
   <![CDATA[

     [Bindable]
     public var someVar:String;

     public function init(e:Event):void
     {
       someVar = "Created";
     }
   ]]>
   <mx:Script>
</mx:Canvas>

It is equivalent to MyCanvas.as that contains:

package
{
  import mx.containers.Canvas;
  import mx.controls.Label;
  import mx.binding.utils.BindingUtils;

  [Bindable]
  public var someVar:String;

  [Bindable]
  public var theLabel:Label;

  public class MyCanvas extends Canvas
  {
    this.width = 200;
    this.addEventListener(FlexEvent.CREATION_COMPLETE, init);
  }

  public function init(e:Event):void
  {
    someVar = "Created";
  }

  override protected function createChildren():void
  {
    theLabel = new Label();
    addChild(theLabel);
    BindingUtils.bindProperty(theLabel, "text", this, "someVar");
  }
}

If you look at the code of any Flex class (like UIComponent, Canvas etc), you'll see that they're all .as files rather than .mxml.

Amarghosh