0
OK,我知道這不會聽起來是這樣,但我以前是在版本AS3真的好到Flex之前4需要Flex創建DataGrid和用扇形圖4 AS3
我用能夠使用AS3和零MXML創建任何東西。
這使用MXML很好,但我有一系列的問題,當我嘗試在AS3中做同樣的事情。
下面是兩個代碼:
<?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"
minWidth="640"
minHeight="480"
width="100%" height="100%"
creationComplete="creationCompleteHandler();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RemoteObject id="remotesvc" destination="ColdFusion" source="testCF-debug/cfc/myEmployees" showBusyCursor="true">
<mx:method name="getEmployees" result="getEmployeesResult(event)" fault="getEmployeesFail(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="remoteDepartment" destination="ColdFusion" source="testCF-debug/cfc/myDepartments" showBusyCursor="true">
<mx:method name="getDepartments" result="getDepartmentsResult(event)" fault="getDepartmentsFail(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
.headerCustomStyle
{
color: #ffffff;
backgroundColor: #6b6767;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.charts.Legend;
import mx.charts.PieChart;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var dgHeaderStyles:CSSStyleDeclaration;
[Bindable] private var myUsers:ArrayCollection;
public function init():void{
}
private function getEmployeesResult(event:ResultEvent):void {
employeesDg.dataProvider = event.result as ArrayCollection;
}
private function getEmployeesFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function getDepartmentsResult(event:ResultEvent):void {
departmentChart.dataProvider = event.result as ArrayCollection;
}
private function getDepartmentsFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function creationCompleteHandler():void{
remotesvc.getEmployees();
remoteDepartment.getDepartments();
}
]]>
</fx:Script>
<s:Panel title="Employees and Departments" id="empDept">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<mx:DataGrid id="employeesDg" x="10" y="88" headerStyleName="headerCustomStyle" chromeColor="{0x6b6767}">
<mx:columns>
<mx:DataGridColumn dataField="id" />
<mx:DataGridColumn dataField="firstname" />
<mx:DataGridColumn dataField="lastname" />
<mx:DataGridColumn dataField="title" />
<mx:DataGridColumn dataField="departmentid" />
<mx:DataGridColumn dataField="officephone" />
<mx:DataGridColumn dataField="cellphone" />
<mx:DataGridColumn dataField="email" />
<mx:DataGridColumn dataField="street" />
<mx:DataGridColumn dataField="city" />
<mx:DataGridColumn dataField="state" />
<mx:DataGridColumn dataField="zipcode" />
<mx:DataGridColumn dataField="office" />
<mx:DataGridColumn dataField="photofile">
<mx:itemRenderer>
<fx:Component>
<mx:Image height="20" />
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:HBox>
<mx:PieChart id="departmentChart" height="100%" width="100%">
<mx:series>
<mx:PieSeries field="budget" nameField="name" labelPosition="callout">
</mx:PieSeries>
</mx:series>
</mx:PieChart>
<mx:Legend dataProvider="{departmentChart}" />
</mx:HBox>
</s:Panel>
</s:Application>
<?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"
minWidth="640"
minHeight="480"
width="100%" height="100%"
creationComplete="creationCompleteHandler();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:RemoteObject id="remotesvc" destination="ColdFusion" source="testCF-debug/cfc/myEmployees" showBusyCursor="true">
<mx:method name="getEmployees" result="getEmployeesResult(event)" fault="getEmployeesFail(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="remoteDepartment" destination="ColdFusion" source="testCF-debug/cfc/myDepartments" showBusyCursor="true">
<mx:method name="getDepartments" result="getDepartmentsResult(event)" fault="getDepartmentsFail(event)"/>
</mx:RemoteObject>
</fx:Declarations>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
.headerCustomStyle
{
color: #ffffff;
backgroundColor: #6b6767;
}
</fx:Style>
<fx:Script>
<![CDATA[
import flash.utils.flash_proxy;
import mx.charts.Legend;
import mx.charts.PieChart;
import mx.charts.chartClasses.Series;
import mx.charts.series.ColumnSeries;
import mx.charts.series.PieSeries;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var employeesDg:DataGrid;
private var employeesCol1:DataGridColumn;
private var employeesCol2:DataGridColumn;
private var employeesCol3:DataGridColumn;
private var employeesCol4:DataGridColumn;
private var employeesCol5:DataGridColumn;
private var employeesCol6:DataGridColumn;
private var employeesCol7:DataGridColumn;
private var employeesCol8:DataGridColumn;
private var employeesCol9:DataGridColumn;
private var employeesCol10:DataGridColumn;
private var employeesCol11:DataGridColumn;
private var employeesCol12:DataGridColumn;
private var employeesCol13:DataGridColumn;
private var employeesCol14:DataGridColumn;
private var departmentChart:PieChart;
private var departmentChartPieSeries:PieSeries;
private var departmentChartSeries:Series;
private var departmentLegend:Legend;
private var departmentChartHbox:HBox;
private var dgHeaderStyles:CSSStyleDeclaration;
[Bindable] private var myUsers:ArrayCollection;
public function init():void{
departmentChartHbox = new HBox();
departmentChartHbox.id = "departmentChartHbox";
employeesDg = new DataGrid();
employeesDg.id = "employeesDg";
employeesDg.x = 10;
employeesDg.y = 88;
employeesDg.styleName = "";
// employeesDg.headerStyleName="headerCustomStyle";
employeesDg.chromeColor="{0x6b6767}";
employeesCol1 = new DataGridColumn;
employeesCol2 = new DataGridColumn;
employeesCol3 = new DataGridColumn;
employeesCol4 = new DataGridColumn;
employeesCol5 = new DataGridColumn;
employeesCol6 = new DataGridColumn;
employeesCol7 = new DataGridColumn;
employeesCol8 = new DataGridColumn;
employeesCol9 = new DataGridColumn;
employeesCol10 = new DataGridColumn;
employeesCol11 = new DataGridColumn;
employeesCol12 = new DataGridColumn;
employeesCol13 = new DataGridColumn;
employeesCol14 = new DataGridColumn;
employeesCol1.dataField = "id";
employeesCol2.dataField = "firstname";
employeesCol3.dataField = "lastname";
employeesCol4.dataField = "title";
employeesCol5.dataField = "departmentid";
employeesCol6.dataField = "officephone";
employeesCol7.dataField = "cellphone";
employeesCol8.dataField = "email";
employeesCol9.dataField = "street";
employeesCol10.dataField = "city";
employeesCol11.dataField = "state";
employeesCol12.dataField = "zipcode";
employeesCol13.dataField = "office";
employeesCol14.dataField = "photofile";
employeesCol14.itemRenderer;
employeesDg.addChild(employeesCol1);
employeesDg.addChild(employeesCol2);
employeesDg.addChild(employeesCol3);
employeesDg.addChild(employeesCol4);
employeesDg.addChild(employeesCol5);
employeesDg.addChild(employeesCol6);
employeesDg.addChild(employeesCol7);
employeesDg.addChild(employeesCol8);
employeesDg.addChild(employeesCol9);
employeesDg.addChild(employeesCol10);
employeesDg.addChild(employeesCol11);
employeesDg.addChild(employeesCol12);
employeesDg.addChild(employeesCol13);
employeesDg.addChild(employeesCol14);
departmentChartHbox.addChild(employeesDg);
departmentChart = new PieChart();
departmentChart.id = "departmentChart";
departmentChart.height = 320;
departmentChart.width = 240;
departmentChartSeries = new Series();
departmentChart.addChild(departmentChartSeries);
departmentChartPieSeries = new PieSeries();
departmentChartPieSeries.field = "budget";
departmentChartPieSeries.nameField = "name";
// departmentChartPieSeries.labelPosition = "callout";
departmentChartSeries.addChild(departmentChartPieSeries);
departmentLegend = new Legend();
departmentLegend.dataProvider = departmentChart;
departmentLegend.id = "departmentLegend";
departmentChartHbox.addChild(departmentChart);
departmentChartHbox.addChild(departmentLegend);
empDept.addChild(departmentChartHbox);
}
private function getEmployeesResult(event:ResultEvent):void {
employeesDg.dataProvider = event.result as ArrayCollection;
}
private function getEmployeesFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function getDepartmentsResult(event:ResultEvent):void {
departmentChart.dataProvider = event.result as ArrayCollection;
}
private function getDepartmentsFail(event:FaultEvent):void {
Alert.show(event.toString());
}
private function creationCompleteHandler():void{
remotesvc.getEmployees();
remoteDepartment.getDepartments();
}
]]>
</fx:Script>
<s:Panel title="Employees and Departments" id="empDept">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:Panel>
</s:Application>
我無法弄清楚如何添加的itemRenderer或如何導入FX:組件,等...
我怎麼做在AS3中同樣的東西?
如果你應該問「爲什麼?」,那是因爲我想創建一個按鈕,通過點擊一個調用函數的按鈕來改變PieSeries field =「budget」nameField =「name」做這樣的事情:
myPieSeries.field="expectedCosts";
隨後新的數據反映在PieChart中。
在此先感謝
你可能想在這裏減少代碼量。根據我的經驗,如果它太大,沒有多少人會通過你的代碼讀取錯誤來查找錯誤。 –
當我最初發布時,我一直在想同樣的事情。回答我自己的問題,並提出一系列新問題。 – kronus