我正在尝试使用mxml文件中的ActionScript DataGrid组件。 但它给我一些错误。
以下是我的主要申请文件。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:local="*" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Metadata>
[Event(name="myEvent", type="flash.events.Event")]
</mx:Metadata>
<mx:Button label="Button"/>
<mx:Array id="arr">
<mx:Object From="Phill" Subject="GMC-1 Release" Date="12/08/06" CC="Jim" Profit="69" />
<mx:Object From="Harry" Subject="GMC-1 Release" Date="12/08/06 11111111" CC="Ram" Profit="10" />
<mx:Object From="Barb" Subject="GMC-1 Release" Date="12/08/06" CC="Anant" Profit="20" />
<mx:Object From="Amit" Subject="GMC-1 Release" Date="12/07/06" CC="Jim" Profit="28" />
<mx:Object From="Sam" Subject="GMC-1 Release" Date="12/08/06" CC="Jim" Profit="17" />
<mx:Object From="Phill" Subject="GMC-2 Release" Date="12/11/06" CC="Jim" Profit="10" />
<mx:Object From="John" Subject="Grid scrolling" Date="12/10/06" CC="Craig" Profit="20" />
<mx:Object From="Bob" Subject="ItemRenderers" Date="12/10/06" CC="Moxie" Profit="11" />
</mx:Array>
<local:AutoResizableADG id="adg" dataProvider="{arr}" width="400" height="400" >
<local:columns>
<mx:AdvancedDataGridColumn headerText="From" dataField="From" width="50" />
<mx:AdvancedDataGridColumn headerText="Subject" dataField="Subject" width="50" />
<mx:AdvancedDataGridColumn headerText="Date" dataField="Date" width="70" />
<mx:AdvancedDataGridColumn headerText="CC" dataField="CC" />
</local:columns>
</local:AutoResizableADG>
</mx:Application>
和AutoResizableADG.as
文件在同一个包中..即src /(default-package)
// ActionScript file
package // Line where it is showing error.
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.text.TextLineMetrics;
import mx.controls.AdvancedDataGrid;
import mx.controls.Alert;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.IUIComponent;
import mx.core.UIComponent;
public class AutoResizableADG extends AdvancedDataGrid
{
var sepArray:Array = new Array();
public function AutoResizableADG()
{
// call super
super();
}
/**
* Returns the header separators between column headers,
* and populates the <code>separators</code> Array with the separators returned.
*
* @param i The number of separators to return.
*
* @param seperators Array to be populated with the header objects.
*
* @param headerLines The parent component of the header separators.
* Flex calls the <code>headerLines.getChild()</code> method internally to return the separators.
*/
override protected function getSeparator(i:int, seperators:Array, headerLines:UIComponent):UIComponent
{
var sep:UIComponent = super.getSeparator(i, seperators, headerLines);
sep.doubleClickEnabled = true;
// Add listener for Double Click
DisplayObject(sep).addEventListener(myEvent.myEvent, hello);
// Alert.show(""+sep);
sepArray.push(sep);
return sep;
}
public function getListItems():Array{
return listItems;
}
/**
* @private
* Indicates where the right side of a resized column appears.
*/
public function hello(event:UIComponent):void
{
// check if the ADG is enabled and the columns are resizable
if (!enabled || !resizableColumns)
return;
var target:DisplayObject = DisplayObject(event);
var index:int = target.parent.getChildIndex(target);
// get the columns array
var optimumColumns:Array = getOptimumColumns();
// check for resizable column
if (!optimumColumns[index].resizable)
return;
// calculate the maxWidth - we can optimize this calculation
if(listItems)
{
var len:int = listItems.length;
var maxWidth:int = 0;
for(var i:int=0;i<len;i++)
{
if(listItems[i][index] is IDropInListItemRenderer)
{
var lineMetrics:TextLineMetrics = measureText(IDropInListItemRenderer(listItems[i][index]).listData.label);
if(lineMetrics.width > maxWidth)
maxWidth = lineMetrics.width ;
}
}
}
// set the column's width
optimumColumns[index].width = maxWidth + getStyle("paddingLeft") + getStyle("paddingRight") + 8;
}
}
}
它向我显示了ActionScript文件中的错误....
"Packages cannot be nested"
为什么会这样?有什么问题?
答案 0 :(得分:0)
我不确定为什么它没有编译,但你是否尝试将AutoResizableADG.as放入实际包中以查看它是否解决了问题?
E.g。
// ActionScript file
package myPackage
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.text.TextLineMetrics;
import mx.controls.AdvancedDataGrid;
import mx.controls.Alert;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.IUIComponent;
import mx.core.UIComponent;
public class AutoResizableADG extends AdvancedDataGrid
{
....
答案 1 :(得分:0)
这种行为我称之为古怪,但记录在案。我发现了两个问题:
两种方法都以相同的原则运作 祝你好运!