我想從mxml文件中使用ActionScript DataGrid組件。 但它顯示我一些錯誤。包不能嵌套 - as3
以下是我的主要應用程序文件。
<?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 /(缺省封裝)
// 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"
這是怎麼發生的?問題是什麼 ?
您的代碼似乎正確 - 我已將其複製並粘貼到我的編輯器,並且沒有顯示「程序包無法嵌套」錯誤。它可能與您的文件夾結構有關嗎(無名包總是最常用的源文件夾)?那個超級班呢?你在使用哪個IDE?如果您在Flash Builder或FDT中,請嘗試「項目 - >清理」。 – weltraumpirat 2012-02-12 09:34:41
我只使用你的代碼設置了一個新項目。我得到了AutoResizableADG類的編譯錯誤,說'myEvent'是一個未定義的屬性,這是你的問題嗎?我唯一的代碼是你的類和上面的應用程序代碼,都在默認包中。 – Jeremy 2012-02-29 22:17:58