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()">
发表评论
-
[转]Flex中[Bindable]的用法
2012-01-20 02:50 475[转]Flex中[Bindable]的用法 2010年06月 ... -
Flex学习笔记(1)
2012-01-20 02:50 503Flex学习笔记(1) 2010年06 ... -
接下来做什么
2012-01-20 02:50 486接下来做什么 2010年10 ... -
Python编程简介
2012-01-20 02:50 932Python编程简介 2011年06月23日 NOTE: ... -
神马都是浮云。
2012-01-19 10:43 607神马都是浮云。 2011年04月15日 ... -
2011的神马,浮云。。
2012-01-19 10:43 6412011的神马,浮云。。 2011年12月27日 年尽, ... -
神马都是浮云
2012-01-19 10:43 527神马都是浮云 2011年03 ... -
神马都是浮云~ ~我们的第一个学期
2012-01-19 10:43 557神马都是浮云~ ~我们的第一个学期 2012年01月13日 ... -
神马都不是浮云
2012-01-19 10:42 647神马都不是浮云 2011年12月24日 ... -
操作系统结构
2012-01-17 03:13 564操作系统结构 2010年10月20日 操作系统结构 ... -
python教程入门《3》
2012-01-17 03:13 676python教程入门《3》 2011 ... -
2011-2-12
2012-01-17 03:13 8502011-2-12 2011年02月12日 HTC G2 ... -
计算机英语词汇大全(1)
2012-01-17 03:13 583计算机英语词汇大全(1) ... -
as3面试题
2012-01-17 03:13 704as3面试题 2011年09月13日 ... -
宝贝就这些了!
2012-01-16 01:47 627宝贝就这些了! 2011年05 ... -
执一不二 跬步千里-王子密码2011年11月份心得(十)
2012-01-16 01:47 605执一不二 跬步千里-王 ... -
把握时机比业绩、才干更重要
2012-01-16 01:47 606把握时机比业绩、才干 ... -
2011年不给自己留下任何遗憾
2012-01-16 01:47 5822011年不给自己留下任何遗憾 2011年12月17日 ... -
7位模式服务体系
2012-01-16 01:47 5657位模式服务体系 2011年 ... -
the observer pattern 观察者模式
2012-01-11 01:38 547the observer pattern 观察者模式 201 ...
相关推荐
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类生成工具,简单实用!