What are the differences between flex mxml and actionscript-3

What is the difference between flex mxml and as3.

+6
flex actionscript-3
source share
3 answers

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

The Flex compiler converts MXML markup to ActionScript-3 code before compiling it to SWF / SWC. Most of the things you do in MXML can also be done using ActionScript, but this will require more lines of code.

The MXML file creates an ActionScript class with 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 the MyCanvas class, which 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 , which 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 (for example, UIComponent , Canvas , etc.), you will see that these are all .as files, not .mxml .

+16
source share

MXML is a declarative language for defining the user interface elements of your views in a Flex application. You can also declare some non-UI elements that exist and support the page, but for the most part they are simply used for user interface elements.

AS3 are programming languages ​​that are used to add all the logic and functionality to your application.

Both are connected to each other through events and data binding.

0
source share

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

See what happens in actionscript, you need to solve the parent and child, so it becomes a little complicated, you need to code everything for every n,

eg.

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

but in case of mxml u only one tag is needed

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

therefore it’s easier to work in mxml, but there are some limitations of mxml, so sooner or later you will have to use ActionScript, this is what we all do daily

I hope you have an idea tc havw a gr8 day

0
source share

All Articles