加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex mxml和actionscript-3有什么区别

发布时间:2020-12-15 02:16:06 所属栏目:百科 来源:网络整理
导读:flex mxml和as3有什么区别. 解决方法 M XML是一种基于 XML的标记语言,用于使用Flex框架方便地定义用户界面和数据绑定. MXML文件可以包含 mx:Script内的ActionScript.标签 – 类似于如何在html文件中使用javascript. Flex编译器在将MXML标记编译为SWF / SWC
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读