flex mxml和as3有什么区别.
解决方法
M
XML是一种基于
XML的标记语言,用于使用Flex框架方便地定义用户界面和数据绑定. MXML文件可以包含< mx:Script>内的ActionScript.标签 – 类似于如何在html文件中使用javascript.
Flex编译器在将MXML标记编译为SWF / SWC之前将其转换为ActionScript-3代码.您在MXML中执行的大多数操作也可以使用ActionScript完成,但是需要更多行代码才能完成.
mxml文件创建一个同名的actionscript类,用于扩展与mxml文件的根标记对应的类.例如,MyCanvas.mxml中的以下代码生成扩展Flex Canvas类的MyCanvas类.
<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>
它相当于包含以下内容的MyCanvas.as:
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");
}
}
如果你看一下任何Flex类的代码(比如UIComponent,Canvas等),你会发现它们都是.as文件而不是.mxml.