- 浏览: 11060 次
最新评论
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()">
发表评论
-
next version flex ,odenamed “Hero”
2012-01-20 01:27 621next version flex ,odenamed “He ... -
Flex和Java 整合
2012-01-20 01:27 513Flex和Java 整合 2010年07月21日 Fle ... -
flex ant 例子
2012-01-20 01:27 659flex ant 例子 2011年03月10日 ... -
Delphi 内存机制 调试教程
2012-01-19 09:17 756Delphi 内存机制 调试教程 2011年10月21日 ... -
Rundll32.exe文件详解
2012-01-19 09:17 545Rundll32.exe文件详解 2010年07月16日 ... -
Rundll32.exe使用方法大全
2012-01-19 09:17 537Rundll32.exe使用方法大全 ... -
程序如何关联后缀为mte的文件
2012-01-19 09:17 663程序如何关联后缀为mte ... -
VC++6.0实现超链接
2012-01-19 09:17 1061VC++6.0实现超链接 2011年 ... -
显卡驱动更新完后还是找不到合适的分辨率的应对方法
2012-01-17 01:50 718显卡驱动更新完后还是 ... -
[SU] 如何使SketchUp跑得更快(上)――专业教程系列
2012-01-17 01:50 663[SU] 如何使SketchUp跑得更快(上)――专业教程系列 ... -
电脑检测软件列表及电脑硬件驱动大全
2012-01-17 01:50 986电脑检测软件列表及电脑硬件驱动大全 2011年02月27日 ... -
2011-5-3
2012-01-17 01:49 7402011-5-3 2011年05月03日 电脑检测软件列 ... -
socket性能优化(上)
2012-01-15 21:00 463socket性能优化(上) 2012 ... -
诬凹沃官燠喷闳
2012-01-15 21:00 503诬凹沃官燠喷闳 2012年01月06日 U辙趴“ ... -
是傻频日志呵阡啄凛仄
2012-01-15 21:00 510是傻频日志呵阡啄凛仄 2012年01月09日 刘 ... -
socket性能优化(上)
2012-01-15 21:00 461socket性能优化(上) 2012 ... -
诬凹沃官燠喷闳
2012-01-15 21:00 255诬凹沃官燠喷闳 2012年01月06日 U辙趴“ ...
相关推荐
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类生成工具,简单实用!