`
ylr34ylr
  • 浏览: 11904 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Flex中的set啊Flex中的set

 
阅读更多

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例程一,关于如何建GET,SET

    flex例程一,好不容易找到的。关于如何建GET,SET关于如何建GET,SET

    Flex 生成 get set 小工具

    flex 生成geter seter 工具,简单实用。无需安装,swf 格式,方便实用。

    Iframe(Flex嵌入完整网页的类)

    在Flex中嵌入完整的网页所用到的类, xmlns:flexiframe="com.google.code.flexiframe.*" <flexiframe:IFrame id="helpFrame" source="assets/dreamweaver/help/helpHome....

    ArcGIS API for Flex 2.5

    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 集成到 Java EE 应用程序的最佳实践(完整源代码)

    因此,需要一个 FactoryInstance 的实现类,我们编写一个 SpringFactoryInstance,以便从 Spring 的容器中查找 FlexService: 清单 9. SpringFactoryInstance class class SpringFactoryInstance extends ...

    Adobe Flex 4.5 Fundamentals

    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 ...

    +Flex+集成到+Java+EE+应用程序的最佳实践(完整源代码)

    因此,需要一个 FactoryInstance 的实现类,我们编写一个 SpringFactoryInstance,以便从 Spring 的容器中查找 FlexService: 清单 9. SpringFactoryInstance class class SpringFactoryInstance extends ...

    MyBatis-Generator 自动生成Lombok标签 不生成Get/Set方法

    把下载的jar包放在 Maven仓库的 org\mybatis\generator\mybatis-generator-core\1.3.5 下面即可,然后在generatorConfig配置文件中加上 </plugin> 即可

    Forex-Flex-EA.rar_K-Flex Files_flex EA_forex ea_forex flex_forex

    mql 4 forex flex ea. including indicators and set files

    Flex 3 in Action

    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 ...

    ArcGIS_Flex开发包

    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...

    ArcGIS API for Flex 2.0

    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跨域上传

    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_...

    ArcGIS API for Flex 2.4

    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...

    ArcGIS API for Flex 2.2

    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...

    ArcGIS API for Flex 2.3

    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...

    ArcGIS API for Flex 3.0

    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导出excel的代码

    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

    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类生成工具

    as get set类生成工具,简单实用!

Global site tag (gtag.js) - Google Analytics