Flex中的set啊Flex中的set
2010年10月17日
Flex中的set function就是给属性赋值的,说起来简单,但是遇到一个相关的bug还真晕。其实几天前就遇到类似问题了,我没有深究,赶进度嘛。今天晚上Alan修一个bug的时候又遇到了,作为小leader,我就得帮他解惑。正好自己也研究下,就算晚上没白等QA做build了。刚刚又上网找了找,还真没类似的文章,那我这个算原创了吧?哇咔咔……和大家分享吧,说不定有谁遇到类似的问题,痛苦半天呢。(已经知道答案的也不要鄙视我,毕竟我也是新手不是?)
问题:Flex中的set在什么情况下不起作用?
言归正传,先说说这个问题的由来吧:
ModelLocator.getInsternce().buildModel.selectedBui ldVo = vo;
就是代码中的这句话,设了断点怎么也跑不进去(selectedBuildVo是一个set function)在这个set中,有一点逻辑来处理vo中的一些数据的,从而改变绑定在页面上的一个对象。
不绕弯子了,上面那个问题的答案是:当set中的值在内存中的地址和所要赋值的对象的地址一样时,也就是说,selectBuildVo和vo的地址一样时(同一个对象),这个set不起作用,当然,set中的逻辑也不会跑起来。这个和函数还是不一样的,function的话,什么时候调用,什么时候就会老老实实去跑的……
同时,让我郁闷的是,第一次遇到这样的情况,原来没一点类似经验啊,根本不会往这个地方想,呵呵。教条主义害死人啊,谁也没和我数过给一个set function赋值的时候一定会跑进去啊。看来以后还是需要多用方法,别什么都省事,想用set function来实现。
作为一种习惯,我顺带把这个问题和.net中的set对比了一下,发现Flex的set和.net的set还真不一样,哈哈,.net中的set,无论什么时候赋值,都会乖乖响应的……
============================
下面贴出证明上述结论的codes,先.net吧:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class TestVo
{
public TestVo() { }
public string test = "TEST";
}
class Program
{
static TestVo _vo1;
static TestVo vo1
{
get { return _vo1; }
set { Console.WriteLine("Call SET"); _vo1 = value; }
}
static void Main(string[] args)
{
TestVo vo2 = new TestVo();
Console.WriteLine("Try first set, this time the address are NOT same");
vo1 = vo2;
vo2.test = "test2";
Console.WriteLine("Try second set, this time the address are same");
vo1 = vo2;
Console.ReadKey();
}
}
}
下面是Flex的demo:
TestVo.as文件:
package
{
[Bindable]
public class TestVo extends Object
{
public functionTestVo()
{
}
varpublic var test:String="TEST";
}
}
TrySet.mxml文件:
flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
发表评论
-
java面笔试总结
2012-01-20 00:36 612java面笔试总结 2011年04月10日 2010、1 ... -
为什么用*? 为什么不用*?
2012-01-20 00:36 570为什么用*? 为什么不用* ... -
实战 OpenLaszlo 与 db4o
2012-01-20 00:36 600实战 OpenLaszlo 与 db4o 201 ... -
设备状态显示的flex实现说明
2012-01-20 00:36 648设备状态显示的flex实现 ... -
hive基础
2012-01-17 00:54 657hive基础 2011年07月11日 ... -
用CRC保护程序(DELPHI)
2012-01-17 00:54 681用CRC保护程序(DELPHI) 2010年06月07日 ... -
TOAD快速入门(中文经典)
2012-01-17 00:54 738TOAD快速入门(中文经典) ... -
oracle错误一览表三
2012-01-17 00:54 890oracle错误一览表三 2011年02月15日 OR ... -
C库函数
2012-01-15 19:39 475C库函数 2010年06月28日 rename()文件改 ... -
初探Linux kernel之喝凉水系列二
2012-01-15 19:39 516初探Linux kernel之喝凉水系列二 2011年03月 ... -
D200的库设置
2012-01-15 19:39 491D200的库设置 2010年07月2 ... -
win32 与 C库 复制文件的比较
2012-01-15 19:39 667win32 与 C库 复制文件的比较 2009年10月18日 ... -
c库函数和系统调用的区别(很模糊)
2012-01-15 19:39 592c库函数和系统调用的区 ...
相关推荐
flex例程一,好不容易找到的。关于如何建GET,SET关于如何建GET,SET
flex 生成geter seter 工具,简单实用。无需安装,swf 格式,方便实用。
在Flex中嵌入完整的网页所用到的类, xmlns:flexiframe="com.google.code.flexiframe.*" <flexiframe:IFrame id="helpFrame" source="assets/dreamweaver/help/helpHome....
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
因此,需要一个 FactoryInstance 的实现类,我们编写一个 SpringFactoryInstance,以便从 Spring 的容器中查找 FlexService: 清单 9. SpringFactoryInstance class class SpringFactoryInstance extends ...
This latest edition includes complete coverage of new Flex 4.5 features, such as new enhancements to the Spark architecture and component set. It will also show you how to take advantage of the ...
因此,需要一个 FactoryInstance 的实现类,我们编写一个 SpringFactoryInstance,以便从 Spring 的容器中查找 FlexService: 清单 9. SpringFactoryInstance class class SpringFactoryInstance extends ...
把下载的jar包放在 Maven仓库的 org\mybatis\generator\mybatis-generator-core\1.3.5 下面即可,然后在generatorConfig配置文件中加上 </plugin> 即可
mql 4 forex flex ea. including indicators and set files
This chapter makes the case why Flex is a great addition to your personal skill set or your organization. With buzzwords flying all over, a nonstop stream of websites with missing vowels in their ...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
flex跨域上传,需nginx,tomcat host: 127.0.0.1 test1.zwh.com 127.0.0.1 test2.zwh.com nginx: client_max_body_size 2048m; server { listen 80; server_name test2.zwh.com; location / { proxy_set_...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
4. In Adobe Flash Builder, right-click on any of the sample mxml applications and click "Set as Default Application". 5. In Adobe Flash Builder, right-click on any of the sample mxml applications and...
sheet.setCell(0, 0, "Today's date:"); sheet.setCell(0, 1, new Date()); excelFile.sheets.addItem(sheet); var mbytes:ByteArray = excelFile.saveToByteArray(); var stream:FileStream = new ...
flex DataGrid 导出Xls private function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void { var colCount:int = rebateByItemDG.columnCount; for(var c:int; c ; c++) { var i:int = 0; ...
as get set类生成工具,简单实用!