flex mxml 和 actionscript-3 有什么区别 [英] What are the differences between flex mxml and actionscript-3

查看:23
本文介绍了flex mxml 和 actionscript-3 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

flex mxml 和 as3 有什么区别.

What are the differences between flex mxml and as3.

推荐答案

MXML 是一种基于 XML 的标记语言,用于使用 Flex 框架方便地定义用户界面和数据绑定.MXML 文件可以在 <mx:Script> 标签内包含 ActionScript - 类似于在 html 文件中使用 javascript 的方式.

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.

Flex 编译器先将 MXML 标记转换为 ActionScript-3 代码,然后再将其编译为 SWF/SWC.您在 MXML 中所做的大部分事情也可以使用 ActionScript 来完成,但需要更多的代码行来完成.

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.

mxml 文件创建一个同名的 actionscript 类,该类扩展与 mxml 文件的根标记对应的类.例如,MyCanvas.mxml 中的以下代码生成扩展 Flex Canvas 类的 MyCanvas 类.

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>

它等价于包含:

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 类(例如 UIComponentCanvas 等)的代码,您会发现它们都是 .as 文件而不是 .mxml.

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.

这篇关于flex mxml 和 actionscript-3 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆