几个 Flex 例程的代码
来源:百度文库 编辑:神马文学网 时间:2024/04/27 18:54:50
最近在CFLEX看到了几个很好的例子,整理一下发上来。注:所有代码都来自CFLEX。
1.动态创建 DataGrid 列。这个例子是根据XML中的节点值来创建DataGrid中的列,并且还包含了一些对列的属性得设置。
程序代码
creationComplete="initApp()">
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;ioColumnDef = 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;ixmlColumn = 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
]]>
Nokia 6010
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
99.99
assets/pic/Nokia_6010.gif
6000
false
false
MMS
Large color display
Nokia 3100 Blue
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.
139
assets/pic/Nokia_3100_blue.gif
3000
true
false
Glow-in-the-dark
Flashing lights
Nokia 3100 Pink
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.
139
assets/pic/Nokia_3100_pink.gif
3000
true
false
Glow-in-the-dark
Flashing lights
Nokia 3120
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.
159.99
assets/pic/Nokia_3120.gif
3000
true
false
Multimedia messaging
Animated screensavers
Nokia 3220
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.
159.99
assets/pic/Nokia_3220.gif
3000
false
true
MIDI tones
Cut-out covers
2.在 Tree 中查找节点。在对话框中输入要查找的节点的值。
程序代码
[Bindable]
public var _xmlData:XML;
public function initApp():void
{
_xmlData =
;
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
]]>
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
showRoot="false" dataProvider="{_xmlData}" />
3.动态显示/隐藏 DataGrid 的列。在List中选中一个就会显示相应的 DataGrid 的列。
程序代码
creationComplete="initApp()">
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;ibFound = false
dgc = aColumns[i];
sDataField = dgc.dataField;
for (var j:int=0;jsDataFieldCur = aSelectedColumns[j].dataField;
if (sDataFieldCur == sDataField) {
bFound = true;
break;
}
}//for (var j:
if (bFound) {
dgc.visible = true;
}
else {
dgc.visible = false;
}
}// for (var i:
}//
]]>
labelField="dataField"
allowMultipleSelection="true"
click="hideShowColumns()" />
Nokia 6010
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
99.99
assets/pic/Nokia_6010.gif
6000
false
false
MMS
Large color display
Nokia 3100 Blue
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.
139
assets/pic/Nokia_3100_blue.gif
3000
true
false
Glow-in-the-dark
Flashing lights
Nokia 3100 Pink
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.
139
assets/pic/Nokia_3100_pink.gif
3000
true
false
Glow-in-the-dark
Flashing lights
Nokia 3120
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.
159.99
assets/pic/Nokia_3120.gif
3000
true
false
Multimedia messaging
Animated screensavers
Nokia 3220
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.
159.99
assets/pic/Nokia_3220.gif
3000
false
true
MIDI tones
Cut-out covers
1.动态创建 DataGrid 列。这个例子是根据XML中的节点值来创建DataGrid中的列,并且还包含了一些对列的属性得设置。
程序代码
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
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
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
]]>
2.在 Tree 中查找节点。在对话框中输入要查找的节点的值。
程序代码
public var _xmlData:XML;
public function initApp():void
{
_xmlData =
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
]]>
3.动态显示/隐藏 DataGrid 的列。在List中选中一个就会显示相应的 DataGrid 的列。
程序代码
//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
dgc = aColumns[i];
sDataField = dgc.dataField;
for (var j:int=0;j
if (sDataFieldCur == sDataField) {
bFound = true;
break;
}
}//for (var j:
if (bFound) {
dgc.visible = true;
}
else {
dgc.visible = false;
}
}// for (var i:
}//
]]>
allowMultipleSelection="true"
click="hideShowColumns()" />
几个 Flex 例程的代码
推荐几个不错的Flex学习网站
用Flex/Bison分析c代码的经历
几个论坛签名显IP的代码!
博客 模块里常用的几个代码
QQ空间代码-几个不错的代码(JS文件)
几个滚动条代码
强烈推荐几个比较好的Java代码查询网站
强烈推荐几个比较好的Java代码查询网站
强烈推荐几个比较好的Java代码查询网站
强烈推荐几个比较好的Java代码查询网站00
强烈推荐几个比较好的Java代码查询网站
强烈推荐几个比较好的Java代码查询网站bbb
【HTML语言教程】认识一下几个要变化的代码名称
QQ空间代码-几个不错的代码(JS文件)[八百路潮流时尚论坛]
在Flex中内嵌Session的存取操作
在Flex中内嵌Session的存取操作
几个简易音画贴代码
LUA脚本语言使用例程
加速代码文档的编制的几个有效思路 - JAVA - 中国网管联盟 bitsCN.com
缠绵悱恻女人声12首【附:几个特殊的女声代码】
几个博客或网站的代码语法高亮程序(javascript)
使用Flex Message时找不到Destination的解决办法
Flex与Javascript交互 - dante_k7的专栏 - CSDN博客