Flex4.5 中的错误

阅读更多

近期在用Flex4.5 开发项目

 

中途使用一个来显示每一个项的时候,采用标签、、、

 

但是在result中触发事件时,报错如下:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy....

 

        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:local="*"
        creationComplete="xmlReader.send()"
        width="1200" height="768" showStatusBar="false"
        xmlns:ui="ui.*">
 
  
  
 

 
     import com.sap.prototyping.standalone.FileRequest;
   import com.sap.prototyping.util.NativeMenuUtil;
   
   import mx.collections.ArrayCollection;
   import mx.events.FileEvent;
   import mx.events.FlexEvent;
   import mx.rpc.events.ResultEvent;
   import mx.utils.ArrayUtil;
   
   import spark.events.IndexChangeEvent;
   
   [Bindable]
   public var projects:ArrayCollection;
   
   protected function xmlReader_resultHandler(event:ResultEvent):void
   {
    //projects = event.result as ArrayCollection;
    trace("project:"+event.result.projects.project);
    if(event.result.projects.project is ArrayCollection){
     projects = event.result.projects.project;
    }else{
     projects = new ArrayCollection(ArrayUtil.toArray(event.result.projects.project));
    }
   }
   
   protected function list1_changeHandler(event:IndexChangeEvent):void
   {
    // TODO Auto-generated method stub
    
   }
   
  ]]>
 

 
  
   
    
     
      
      
     

    

   
  
 

 

 

最后在网站http://forum.sephiroth.it/showthread.php?8834-ArrayCollection-Error 找到了解决办法。

 

如红色加粗斜体部分、、、:

 

projects = event.result.projects.project;

=============================>>

 

if(event.result.projects.project is ArrayCollection){
     projects = event.result.projects.project;
    }else{
     projects = new ArrayCollection(ArrayUtil.toArray(event.result.projects.project));
    }
 }

其中红色加粗部分之所以再用了一次 标签,是因为在下面的Label要用到【data】这个系统默认的属性,不加的话,会报如下错误:Access of undefined property data。

你可能感兴趣的:(Flex4.5 中的错误)