学习Flex几个值得研究的例程代码

1.动态创建 DataGrid 列。这个例子是根据XML中的节点值来创建DataGrid中的列,并且还包含了一些对列的属性得设置。

<?xml version="1.0" encoding="utf-8"?>
<!-- This example uses the dataProvider to build the dataGrid columns dynamically -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    creationComplete="initApp()">
<mx:Script><![CDATA[
  import mx.controls.dataGridClasses.DataGridColumn;
  import mx.controls.DataGrid;

  import mx.collections.XMLListCollection;
  import mx.controls.Alert;
 
  [Bindable]
private var _xlcCatalog:XMLListCollection;    //the dataProvider for the DG

//run by creationComplete
public function initApp():void
{
    _xlcCatalog = new XMLListCollection(xmlCatalog.product);  //wrap the XML product nodes in an XMLListCollection
    buildDG();                                                //creates the dataGrid
}//initApp

private function buildDG():void
  {
    var aColumnDef:Array = getColumnDefArray();                  //returns a noraml array of objects that specify DtaGridColumn properties
    var oColumnDef:Object;
    var dg:DataGrid = new DataGrid;                              //instantiate a new DataGrid
    var dgc:DataGridColumn;
    var aColumnsNew:Array = dg.columns
    var iTotalDGWidth:int = 0;
    for (var i:int=0;i<aColumnDef.length;i++)  {                  //loop over the column definition array
      oColumnDef = aColumnDef[i];
      dgc = new DataGridColumn();                                  //instantiate a new DataGridColumn
      dgc.dataField = oColumnDef.dataField;                        //start setting the properties from the column def array
      dgc.width = oColumnDef.width;
      iTotalDGWidth += dgc.width;                                  //add up the column widths
      dgc.editable = oColumnDef.editable;
      dgc.sortable = oColumnDef.sortable
      dgc.visible = oColumnDef.visible;
      dgc.wordWrap = oColumnDef.wordWrap;
      aColumnsNew.push(dgc)                                        //push the new dataGridColumn onto the array
    }
   
    dg.columns = aColumnsNew;                                      //assign the array back to the dtaGrid
    dg.editable = true;
    dg.width = iTotalDGWidth;
    dg.dataProvider = _xlcCatalog;                                 //set the dataProvider 
    this.addChild(dg);                                             //add the dataGrid to the application
  }//buildDG

//uses the first product node to define the columns
private function getColumnDefArray():Array
{
    //Alert.show("colcount:" + xmlCatalog.toXMLString());
    var aColumns:Array = new Array();
    var node0:XML = xmlCatalog.product[0];                          //get the first "product" node
    var xlColumns:XMLList = node0.children();                        //get its child nodes (columns) as an XMLList
    var xmlColumn:XML
    var oColumnDef:Object;
    for (var i:int=0;i<xlColumns.length();i++)  {                    //loop over the xmlList
      xmlColumn = xlColumns[i];
      oColumnDef = new Object();
      oColumnDef.dataField = xmlColumn.localName();                  //make the dataField be the node name
      switch (oColumnDef.dataField)  {                              //conditional column property logic
        case "name":
          oColumnDef.width = 80;
          oColumnDef.sortable = false;
          oColumnDef.visible = true;
          oColumnDef.editable = false;
          oColumnDef.wordWrap = false;        
          break;
        case "description":
          oColumnDef.width = 200;
          oColumnDef.sortable = false;
          oColumnDef.visible = true;
          oColumnDef.editable = false;
          oColumnDef.wordWrap = true;        
          break;
        case "price":
          oColumnDef.width = 40;
          oColumnDef.sortable = true;
          oColumnDef.visible = true;
          oColumnDef.editable = true;
          oColumnDef.wordWrap = false;         
          break;
        case "image":
          oColumnDef.width = 100;
          oColumnDef.sortable = false;
          oColumnDef.visible = false;
          oColumnDef.editable = false;
          oColumnDef.wordWrap = false;        
          break;
        default:
          oColumnDef.width = 50;
          oColumnDef.sortable = true;
          oColumnDef.visible = true;
          oColumnDef.editable = false;
          oColumnDef.wordWrap = false;         
          break;                           
      }
      aColumns.push(oColumnDef);
    }
    return aColumns;                                                    //return the array
}//getColumnDefArray
]]></mx:Script>

  <mx:XML id="xmlCatalog">
    <catalog>
      <product productId="1">
        <name>Nokia 6010</name>
        <description>Easy to use without sacrificing style, the Nokia 6010 phone offers functional voice communication supported by text messaging, multimedia messaging, mobile internet, games and more</description>
        <price>99.99</price>
        <image>assets/pic/Nokia_6010.gif</image>
        <series>6000</series>
        <triband>false</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>MMS</highlight1>
      <highlight2>Large color display</highlight2>
      </product>
      <product productId="2">
        <name>Nokia 3100 Blue</name>
        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
        <price>139</price>
        <image>assets/pic/Nokia_3100_blue.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Glow-in-the-dark</highlight1>
      <highlight2>Flashing lights</highlight2>
      </product>
      <product productId="3">
        <name>Nokia 3100 Pink</name>
        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
        <price>139</price>
        <image>assets/pic/Nokia_3100_pink.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Glow-in-the-dark</highlight1>
      <highlight2>Flashing lights</highlight2>
      </product>
      <product productId="4">
        <name>Nokia 3120</name>
        <description>Designed for both business and pleasure, the elegant Nokia 3120 phone offers a pleasing mix of features. Enclosed within its chic, compact body, you will discover the benefits of tri-band compatibility, a color screen, MMS, XHTML browsing, cheerful screensavers, and much more.</description>
        <price>159.99</price>
        <image>assets/pic/Nokia_3120.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Multimedia messaging</highlight1>
      <highlight2>Animated screensavers</highlight2>
      </product>
      <product productId="5">
        <name>Nokia 3220</name>
        <description>The Nokia 3220 phone is a fresh new cut on some familiar ideas - animate your MMS messages with cute characters, see the music with lights that flash in time with your ringing tone, download wallpapers and screensavers with matching color schemes for the interface.</description>
        <price>159.99</price>
        <image>assets/pic/Nokia_3220.gif</image>
        <series>3000</series>
        <triband>false</triband>
        <camera>true</camera>
        <video>false</video>
        <highlight1>MIDI tones</highlight1>
      <highlight2>Cut-out covers</highlight2>
      </product>
    </catalog>
  </mx:XML>
</mx:Application>

2.在 Tree 中查找节点。在对话框中输入要查找的节点的值。

<?xml version="1.0" encoding="utf-8"?>
<!-- Searchable Tree control example. uses e4x expression to find a node with matching id attribute-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script><![CDATA[
  [Bindable]
  public var _xmlData:XML;
 
  public function initApp():void
  {
    _xmlData = <element eid="hello">
         <element eid="world">
            <element eid="123"/>
            <element eid="graham"/>
            <element eid="weldon">
               <element eid="office">
                  <element eid="thing"/>
                  <element eid="boat"/>
                  <element eid="chair"/>
               </element>
               <element eid="person"/>
                </element>
             </element>
          </element> ;
   trace("test")
  }//initapp 
  //starts at the given node, walks up the tree opening nodes as it goes
  private function expandParents(xmlNode:XML):void
  {
    while (xmlNode.parent() != null) { 
      xmlNode = xmlNode.parent();
      myTree.expandItem(xmlNode,true, false);
    }
  }//expandParents

  //uses e4x to find a node, then calls expand parents to make it visible,
  //then selects it     
private function findNodeById(sId:String):void
{
  var xmllistDescendants:XMLList  = _xmlData.descendants().(@eid == sId);
  expandParents(xmllistDescendants[0]);
  myTree.selectedItem = xmllistDescendants[0];
  }//findNodeById          
]]></mx:Script>
    <mx:Panel title="Tree Control Example" height="75%" width="75%"
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
        <mx:HBox>
          <mx:TextInput id="tiId" text="boat" />
          <mx:Button label="Find" click="findNodeById(tiId.text)" />        
        </mx:HBox>
        <mx:Tree id="myTree" width="50%" height="100%" labelField="@eid"
            showRoot="false" dataProvider="{_xmlData}" />     
    </mx:Panel>
</mx:Application>

3.动态显示/隐藏 DataGrid 的列。在List中选中一个就会显示相应的 DataGrid 的列。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=">http://www.adobe.com/2006/mxml" layout="horizontal" horizontalAlign="left"
    creationComplete="initApp()">
<mx:Script><![CDATA[
  import mx.controls.dataGridClasses.DataGridColumn;
  //import mx.controls.DataGrid;
  import mx.collections.XMLListCollection;
 
  [Bindable]
private var _xlcCatalog:XMLListCollection;    //the dataProvider for the DG

//run by creationComplete
public function initApp():void
{
    _xlcCatalog = new XMLListCollection(xmlCatalog.product);      //wrap the XML product nodes in an XMLListCollection
    lstColumns.selectedItems = new Array(dgHideShow.columns[0]);  //set the column list dataProvider to the DataGridColumns
}//initApp

private function hideShowColumns():void  {
   var aColumns:Array = dgHideShow.columns;
   var aSelectedColumns:Array = lstColumns.selectedItems;
   var dgc:DataGridColumn;
   var sDataField:String;
   var sDataFieldCur:String;
   var bFound:Boolean
   for (var i:int=0;i<aColumns.length;i++)  {
     bFound = false
     dgc = aColumns[i];
     sDataField = dgc.dataField;
     for (var j:int=0;j<aSelectedColumns.length;j++)  {
       sDataFieldCur = aSelectedColumns[j].dataField;
       if (sDataFieldCur == sDataField)  {
         bFound = true;
         break;
       }
     }//for (var j:
     if (bFound) {
       dgc.visible = true;
     } 
     else  {
       dgc.visible = false;
     }    
   }// for (var i:
}//
]]></mx:Script>  
  <mx:VBox>
    <mx:Label text="Multi-Select" />
    <mx:Label text="Columns" />
    <mx:List id="lstColumns" dataProvider="{dgHideShow.columns}"
        labelField="dataField"
        allowMultipleSelection="true"
        click="hideShowColumns()"  />   
  </mx:VBox>

  <mx:DataGrid id="dgHideShow" dataProvider="{_xlcCatalog}" rowCount="6" >
    <mx:columns>
      <mx:Array>
        <mx:DataGridColumn headerText="Product" dataField="name" visible="true" />
        <mx:DataGridColumn headerText="Description" dataField="description" visible="false" />
        <mx:DataGridColumn headerText="Price" dataField="price" visible="false" />
        <mx:DataGridColumn headerText="Series" dataField="series" visible="false" />
        <mx:DataGridColumn headerText="Tri-Band" dataField="triband" visible="false" />
        <mx:DataGridColumn headerText="Camera" dataField="camera" visible="false" />
       </mx:Array>
    </mx:columns>   
  </mx:DataGrid>

  <mx:XML id="xmlCatalog">
    <catalog>
      <product productId="1">
        <name>Nokia 6010</name>
        <description>Easy to use without sacrificing style, the Nokia 6010 phone offers functional voice communication supported by text messaging, multimedia messaging, mobile internet, games and more</description>
        <price>99.99</price>
        <image>assets/pic/Nokia_6010.gif</image>
        <series>6000</series>
        <triband>false</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>MMS</highlight1>
      <highlight2>Large color display</highlight2>
      </product>
      <product productId="2">
        <name>Nokia 3100 Blue</name>
        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
        <price>139</price>
        <image>assets/pic/Nokia_3100_blue.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Glow-in-the-dark</highlight1>
      <highlight2>Flashing lights</highlight2>
      </product>
      <product productId="3">
        <name>Nokia 3100 Pink</name>
        <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
        <price>139</price>
        <image>assets/pic/Nokia_3100_pink.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Glow-in-the-dark</highlight1>
      <highlight2>Flashing lights</highlight2>
      </product>
      <product productId="4">
        <name>Nokia 3120</name>
        <description>Designed for both business and pleasure, the elegant Nokia 3120 phone offers a pleasing mix of features. Enclosed within its chic, compact body, you will discover the benefits of tri-band compatibility, a color screen, MMS, XHTML browsing, cheerful screensavers, and much more.</description>
        <price>159.99</price>
        <image>assets/pic/Nokia_3120.gif</image>
        <series>3000</series>
        <triband>true</triband>
        <camera>false</camera>
        <video>false</video>
        <highlight1>Multimedia messaging</highlight1>
      <highlight2>Animated screensavers</highlight2>
      </product>
      <product productId="5">
        <name>Nokia 3220</name>
        <description>The Nokia 3220 phone is a fresh new cut on some familiar ideas - animate your MMS messages with cute characters, see the music with lights that flash in time with your ringing tone, download wallpapers and screensavers with matching color schemes for the interface.</description>
        <price>159.99</price>
        <image>assets/pic/Nokia_3220.gif</image>
        <series>3000</series>
        <triband>false</triband>
        <camera>true</camera>
        <video>false</video>
        <highlight1>MIDI tones</highlight1>
      <highlight2>Cut-out covers</highlight2>
      </product>
    </catalog>
  </mx:XML>
</mx:Application>

时间: 2024-08-03 09:25:19

学习Flex几个值得研究的例程代码的相关文章

关于学习 Flex 的一点建议(转载)_其它

Flex是什么?RIA(Rich Internet Applications).Flex 是 Macromedia发布的presentation server(展现服务),它是java web container或者.net server的一个应用,根据.mxml文件(纯粹的xml描述文件和actionscript)产生相应得.swf文件,传送到客户端,由客户端的flash player或者shockwave player解释执行,给用户以丰富的客户体验.说这么多,还不如看实例: 苹果树下:ht

Java程序员学习Flex和BlazeDS的十三个理由

在阐述Java程序员应当学习BlazeDS的13条理由时,我以一个假想的苏打分派 系统来展示如何让已有的Java程序转变为RIA应用.通过这个例子,我同时还会 讲解到BlazeDS在已有Java应用或新建Java应用中的多种不同用法. 理由 一:开源 Flex软件开发工具箱(SDK)的核心是个开源框架,专门用来开 发.维护那些在不同浏览器.不同操作系统下界面都相同的RIA应用.Flex发布 采用的是Mozilla公共许可证(Mozilla Public License).编译后的Flex应用 在

Web开发学习心得6——HttpApplication管线研究

经过Asp.net设计思想的研究,我们对HttpApplication的管线已经有了一个本质的了解.所谓管线,实际上就是生产流水线,由一系列的步骤所组成,而HttpContext,就是这条流水线上待加工的产品.现在,我们来对这条生产流水线进行更进一步的了解. 首先请看ApplicationStepManager.BuildSteps方法. 开发学习心得6--HttpApplication管线研究-">1.ValidatePathExecutionStep:负责对请求的路径进行安全检查,禁止

商汤科技曹旭东:为何深度学习几乎成了计算机视觉研究的标配?| 硬创公开课

联合编辑 宗仁 黄鑫雷锋网(公众号:雷锋网)雷锋网雷锋网 今年夏天,雷锋网将在深圳举办一场盛况空前的"全球人工智能与机器人峰会"(简称CCF-GAIR).大会现场,谷歌,DeepMind,Uber,微软等巨头的人工智能实验室负责人将莅临深圳,向我们零距离展示国外人工智能震撼人心.撬动地球的核心所在.如果你不想错过这个大会的盛世狂欢,请点击文末购买我们的早鸟票. 本次CVPR 2016上,深度学习几乎成了如今计算机视觉研究的标配,人脸识别.图像识别.视频识别.行人检测.大规模场景识别的相

Swift学习笔记(一)搭配环境以及代码运行成功

原文:Swift学习笔记(一)搭配环境以及代码运行成功 1.Swift是啥? 百度去!度娘告诉你它是苹果最新推出的编程语言,比c,c++,objc要高效简单.能够开发ios,mac相关的app哦!是苹果以后大力推广的语言哦!   2.Swift给你带来什么机会? 当初你觉得objc太难,学ios学到一半放弃拉,或者进入it行业大家都搞android,你也搞android去了.现在你终于有机会和搞ios的站在一个语言的起跑线上,兄弟!swift传说很容易学哦,搞android的你想不想增加一下本领

大家好,我刚开始学习java,为什么用scanner输入中文代码错误。

问题描述 大家好,我刚开始学习java,为什么用scanner输入中文代码错误. 大家好,我刚开始学习java,为什么用scanner输入中文代码错误.输入英文没有错误 解决方案 控制台输入会有个字符集编码,所以输出你的输入的时候需要进行对象编码 解决方案二: 好像可以设置字符集 你百度下 解决方案三: 设置字符集为UTF-8 解决方案四: windows->preferences-->general-->Context Text 把下属的 都设置为UTF-8 解决方案五: window

深交所:德国创业板的盛衰成败值得研究借鉴

5月23日,深圳证券交易所总经理宋丽萍女士在法兰克福与德国证券交易所签署合作备忘录,双方计划在产品开发.交易平台.信息交换等方面展开一系列合作.适逢深交所筹备启动"创业板"之际,宋丽萍特别关注德交所相应板块发展的经验与教训,记者专门就此对她进行了采访. 宋丽萍介绍,在2000年全球IT行业发展高峰时期,德交所也曾设立"新市场",专门吸收创业初期的IT企业上市.但随着网络泡沫破灭,很多IT企业市值巨幅缩水,该板块也被迫以关闭告终.随后在2005年,德交所又重新开设了一

正则表达式口诀_学习正则的朋友值得一看_正则表达式

签于网上太多的介绍都是一篇凶悍的短文,边看边理解可以,帮助记忆不行.又受五笔字型字根表口诀"白手看头三二斤..."的启发, 试作"正则表达式助记口诀"又名"正则打油诗",版本0.1,绝对原创,仿冒必究,:) 注:本文仅为学习正则时为了便于记忆而作,不能代替系统而全面的学习过程,错漏之处,敬请指正! 正则其实也势利,削尖头来把钱揣:  (指开始符号^和结尾符号$) 特殊符号认不了,弄个倒杠来引路:  (指\. \*等特殊符号) 倒杠后面跟小w, 数

C++开发者快速学习Objective-C语言核“.NET研究”心语法

本文将Objective-C讨论了语言的核心语法.这部分开始详述一些具体的语法.正如你期待的一样,涉及到了定义和类. 类并不是特殊的 在Smalltalk中,类是具有一些特性的对象.在Objective-C中也一样.一个类是一个对象,对象回应消息.Objective-C和C++都分离了对象分配和初始化. 在C++中,对象分配通过新的操作.在Objective-C中,这样的操作是通过给类发送分配消息-调用malloc()或者一个等价. C++中的初始化是通过调用一个与类同名的函数.Objectiv