咖啡伴侣

呆在上海
posts - 163, comments - 156, trackbacks - 0, articles - 2

Flex 添加自定义componemt 到 mxml

Posted on 2008-03-28 09:57 oathleo 阅读(1257) 评论(0)  编辑  收藏 所属分类: Flex
自定义componemt
//////
package web
{
 import mx.controls.DataGrid;
 import mx.core.IFactory;
 
 public class WebPropertySheet extends DataGrid
 {
  public function WebPropertySheet()
  {
   super();
   trace("WebPropertySheet");
  }
  
     override public function get itemRenderer():IFactory
     {
        trace("itemRenderer");
                 return super.itemRenderer;
     }
 }
 }
 
 
 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"  
 xmlns:twaver="web.*"
 layout="absolute"
 creationComplete="service.send()" viewSourceURL="srcview/index.html">
 
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.rpc.events.ResultEvent;
   import com.adobe.serialization.json.JSON;
   
   import web.WebPropertySheet;
   
   private function onJSONLoad(event:ResultEvent):void
   {
    var rawData:String = String(event.result);
   
       var pattern:RegExp = /&nbsp;/gi;
             rawData =  rawData.replace(pattern," ");
      
    var arr:Array = (JSON.decode(rawData) as Array);
    
    var dp:ArrayCollection = new ArrayCollection(arr);
    
    grid.dataProvider = dp;
   }
  ]]>
 </mx:Script>
 
 <mx:HTTPService
  id="service"
  resultFormat="text"
  url="mashedpotato.json"
  result="onJSONLoad(event)" />
 
 <twaver:WebPropertySheet id="grid" right="10" left="10" top="10" bottom="10">
  <twaver:columns>
   <mx:DataGridColumn headerText="Name" dataField="name" />
   <mx:DataGridColumn headerText="Value" dataField="value" />
  </twaver:columns>
 </twaver:WebPropertySheet>
 
</mx:Application>
 
注意
1.在mx:Application属性里定义 xmlns:twaver="web.*"
2.  <twaver:columns> columns是 DataGrid的属性。这里要在mxml 里定义,不能用mx的命名空间,得用自己的命名空间

只有注册用户登录后才能发表评论。


网站导航: