首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

FLEX 中的XML,XMLList,XMLListCollection种练习

2012-08-30 
FLEX 中的XML,XMLList,XMLListCollection类练习留个笔记?xml version1.0 encodingutf-8?s:Applic

FLEX 中的XML,XMLList,XMLListCollection类练习
留个笔记

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"    xmlns:s="library://ns.adobe.com/flex/spark"    xmlns:mx="library://ns.adobe.com/flex/mx"     initialize="init()" minWidth="955" minHeight="600" width="497" height="538"><fx:Script><![CDATA[import mx.collections.Sort;import mx.collections.SortField;import mx.collections.XMLListCollection;private var _projectsXML:XML=<projects><project id="1" name="pro1"><task id="1"><name>UnderStand E4X</name><notes>Cool, for XML anyway</notes></task><task id="2"><name>Learn XMLListCollection</name><notes>simple</notes></task></project><project id="2" name="pro2"><task id="3"><name>Learn XMLList</name></task><task id="4"><name>Get a coffee</name><notes>Very necessary</notes></task></project></projects>private function init():void{var output:String = "";output += "Full XML:\n" + _projectsXML;output += "\n\nUsing E4X and XMLList:\n";output += _projectsXML.project[0].task[0].name + "\n";output += _projectsXML.project.(@name=="pro2").task.(@id==3).name + "\n";var projects:XMLList = _projectsXML.children();for each(var project:XML in projects){output += "Project:" + project.@name + "\n";for each(var task:XML in project.task){output += "  Task:" + task.@id + ": " + task.name;if(task.hasOwnProperty('notes')){output += "(" + task.notes + ")";}output += "\n";}//output += "\n";}output += "\n\nLearning XMLListCollection and Sorting:\n";var allTasks:XMLListCollection = new XMLListCollection(_projectsXML.descendants("task"));var sort:Sort = new Sort();sort.fields =[ new SortField("name",true)];allTasks.sort = sort;allTasks.refresh();output += "\n\n\n" + allTasks + "\n\n\n";for each(var sortedTask:XML in allTasks){output += sortedTask.name + "\n";}outputArea.text = output;}]]></fx:Script><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --></fx:Declarations><s:TextArea id="outputArea" x="0" y="0" width="100%" height="100%"/></s:Application>

热点排行