我有各個食品分類頁面(例如「Carbohyrates」,「Meat」,「Vegetables」等),每個頁面上有3個組合框可以從每個類別中選擇3種不同的配料(即在「肉類」頁面上,用戶可以選擇3種不同類型的肉類)。我寫這3對肉類的共享對象作爲這樣一個數組:在單個列表中顯示sharedpeeddata屬性的multipe數組類型屬性
這裏是我的saveMeat()
功能爲例,所以你能理解我是怎麼形成我的數組:
function saveMeat(event:MouseEvent):void
{
_categoryMeat.btn_goback.removeEventListener(MouseEvent.CLICK, saveMeat);
removeChild(_categoryMeat);
if (meatDisableCheckBox.selected == true)
{
stop();
}
if (myComboBoxMeat.selectedLabel != null)
{
so.data.meat1 = myComboBoxMeat.selectedLabel;
trace(so.data.meat1);
}
if (myComboBoxMeat2.selectedLabel != null)
{
so.data.meat2 = myComboBoxMeat2.selectedLabel;
trace(so.data.meat2);
}
if (myComboBoxMeat3.selectedLabel != null)
{
so.data.meat3 = myComboBoxMeat3.selectedLabel;
trace(so.data.meat3);
}
var meat_items_array:Array = new Array(so.data.meat1, so.data.meat2, so.data.meat3);
so.data.meatItems = meat_items_array;
so.flush();
trace(so.data.meatItems);
}
有幾個這些功能對於每個類別頁面(全部6個不同的功能)。除了複選框和組合框不同之外,它們都非常相似。
我有一個名爲dataLoaded
列表功能加載從共享對象的項目進入滾動列表:
private function dataLoaded():void
{
var i:Number;
for (i=0; i < so.data.meatItems.length; i++) {
_item = new Item();
// creates the var itemTextField //
_itemTextField = new TextField();
_itemTextField.text += '' + so.data.meatItems[i].toString();
//adds textfield to displaylist//
_item.addChild(_itemTextField);
}
}
正如你所看到的,for
迴路輸入我的我的共享對象的屬性之一的toString()
表示( so.data.meatItems
)轉換爲TextField
,但我想輸入我的sharedObject中的所有實例,而不管它們具有哪些子屬性。還要注意,我在評估meatItems
陣列的length
在for
循環條件,如果我想成爲在sharedObject
我該怎麼做評估的所有項目?
編輯:我實現了以下的解決方案,但我收到此錯誤:
TypeError: Error #1010: A term is undefined and has no properties.
at RecipeMatcher/dataLoaded()[/Users/adambull/Desktop/RecipeMatcherSO/RecipeMatcher.as:893]
at RecipeMatcher/displayList()[/Users/adambull/Desktop/RecipeMatcherSO/RecipeMatcher.as:212]
at RecipeMatcher/hideSplashScreen()[/Users/adambull/Desktop/RecipeMatcherSO/RecipeMatcher.as:192]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
這是我在執行下面的嘗試(我已經包括了我的全部功能,這時候萬一有別的東西在我功能造成的問題)
private function dataLoaded():void
{
// parsing of each ingredient//
// instantiation of mcItem (the stage for each item)
for (var item:* in so.data)
{
if (so.data[item] !=null)
{
if (so.data[item] is Array)
{
var a:Array = so.data[item];
for (var i:uint = 0 ; i < a.length;i++)
{
_item = new Item();
// sets //over// layer to invisible/transparent //
_item.item_btn_over.alpha = 0;
// creates the var itemTextField //
_itemTextField = new TextField();
// _itemTextField visual attributes //
_itemTextField.x = _textFieldXPosition + _textFieldPaddingLeft;
_itemTextField.y = _textFieldYPosition;
_itemTextField.selectable = true;
_itemTextField.wordWrap = true;
itemTextField.width = _textFieldWidth;
_itemTextField.height = _textFieldHeight;
_itemTextField.embedFonts = true;
_defaultFormat.color = 0x111112;
_defaultFormat.font = _arialRounded.fontName;
_defaultFormat.size = 18;
_itemTextField.defaultTextFormat = _defaultFormat;
_itemTextField.appendText(so.data[item][i].toString());
//adds textfield to displaylist//
_item.addChild(_itemTextField);
//vertical positioning//
_item.y = i * _itemPosition;
_item.btn_delete.visible = false;
_item.buttonMode = true;
_item.mouseChildren = false;
//adds items to container displaylist//
_container.addChild(_item);
}
}
}
}
// Input Mask//
_mask = new Shape();
_mask.graphics.beginFill(0xFF0000);
_mask.graphics.drawRect(0, 0, _maskWidth, _maskHeight);
_mask.graphics.endFill();
// Positioning of input mask//
// horizontal centering of input mask//
_mask.x = stage.stageWidth/2 - _container.width/2;
_mask.y = _paddingTop;
// adds the mask onto the stage//
addChild(_mask);
// assigns the above mask to the container //
_container.mask = _mask;
// Positioning of container with the mask//
// horizontal centering of container //
_container.x = stage.stageWidth/2 - _container.width/2;
// vertical position of container //
_container.y = _paddingTop;
//Container background stylings//
_background = new Shape();
_background.graphics.drawRect(0, 0, _container.width, _container.height);
_container.addChildAt(_background, 0);
//End of container background stylings//
_item.parent.addEventListener(MouseEvent.CLICK, itemClicked);
_container.addEventListener(MouseEvent.MOUSE_OVER, movingOver);
_container.addEventListener(MouseEvent.MOUSE_OUT, movingOut);
}
(我曾試圖增加額外的if
來評估每個共享對象屬性的內容是否爲空或不? - 因爲我相信,如果一個數組是空的,這可能會導致另一個錯誤)
是的,你沒有正確地理解我的問題。不幸的是,當我實現你的代碼時,它給了我「錯誤#1010:一個術語是未定義的,沒有屬性。」在線891上是'_itemTextField.appendText ...'行? – adaam 2013-04-22 22:01:51
我編輯了我的示例,可以使其適應您的上下文。 – RafH 2013-04-22 22:18:55
仍然收到相同的錯誤,不正確地更新我的問題與堆棧跟蹤+我的解決方案的最新實施 – adaam 2013-04-22 22:35:32