热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在ActionScript中复制复杂的MXML绑定-DuplicatecomplexMXMLbindinginActionScript

MXMLletsyoudosomereallyquitepowerfuldatabindingsuchas:MXML允许您执行一些非常强大的数据绑定,例如:<mx:B

MXML lets you do some really quite powerful data binding such as:

MXML允许您执行一些非常强大的数据绑定,例如:


I've found that the BindingUtils class can bind values to simple properties, but neither of the bindings above do this. Is it possible to do the same in AS3 code, or is Flex silently generating many lines of code from my MXML? Can anyone duplicate the above in pure AS3, starting from:

我发现BindingUtils类可以将值绑定到简单属性,但上面的绑定都没有这样做。是否可以在AS3代码中执行相同操作,或者Flex是否默认从我的MXML生成许多代码行?任何人都可以在纯AS3中复制上述内容,从以下开始:

var myBtn:Button = new Button();
myBtn.id="myBtn";
???

3 个解决方案

#1


2  

The way to do it is to use bindSetter. That is also how it is done behind the scenes when the MXML in your example is transformed to ActionScript before being compiled.

这样做的方法是使用bindSetter。这也是在示例中的MXML在编译之前转换为ActionScript后如何在幕后完成的。

// assuming the itemName property is defined on this:
BindingUtils.bindSetter(itemNameChanged, this, ["itemName"]);

// ...

private function itemNameChanged( newValue : String ) : void {
  myBtn.label   = newValue;
  myBtn.visible = newValue != null;
}

...except that the code generated by the MXML to ActionScript conversion is longer as it has to be more general. In this example it would likely have generated two functions, one for each binding expression.

...除了MXML到ActionScript转换生成的代码更长,因为它必须更通用。在这个例子中,它可能已经生成了两个函数,每个函数对应一个绑定表达式。

#2


2  

You can also view the auto-generated code that flex makes when it compiles your mxml file, by adding a -keep argument to your compiler settings. You can find your settings by selecting your projects properties and looking at the "Flex Compiler" option, then under "Additional compiler arguments:" add "-keep" to what is already there.

您还可以通过在编译器设置中添加-keep参数来查看flex在编译mxml文件时生成的自动生成的代码。您可以通过选择项目属性并查看“Flex编译器”选项找到您的设置,然后在“其他编译器参数:”下添加“-keep”到已存在的内容。

Once done Flex will create a "generated" directory in your source folder and inside you'll find all teh temporary as files that were used during compilation.

完成后,Flex将在源文件夹中创建一个“生成”目录,在内部,您将找到所有临时文件,这些文件是在编译期间使用的。

#3


0  

I believe flex generates a small anonymous function to deal with this.

我相信flex会生成一个小的匿名函数来处理这个问题。

You could do similar using a ChangeWatcher. You could probably even make a new anonymous function in the changewatcher call.

你可以使用ChangeWatcher做类似的事情。您甚至可以在changewatcher调用中创建一个新的匿名函数。


推荐阅读
author-avatar
时刻要有危机感01
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有