さまざまな食品カテゴリ ページ (「炭水化物」、「肉」、「野菜」など) があり、各ページに 3 つのコンボボックスがあり、ユーザーは各カテゴリから 3 つの異なる材料を選択できます (つまり、「肉」ページでは、ユーザーは3種類の肉を選択できます)。次のように、これら 3 つの肉を配列として sharedObject に書き込みます。
例としての私の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
sharedObject からスクロール リストに項目をロードするというリスト関数があります。
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()
sharedObject ( so.data.meatItems
)の属性の 1 つの表現をTextField
に入力しますが、サブ属性に関係なく、sharedObject 内のすべてのインスタンスを入力したいと考えています。また、ループ条件内length
でmeatItems
配列の を評価していることにも注意してください。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
(各共有オブジェクト属性の内容が空であるかどうかを評価するために、エクストラを追加しようとしました。配列が空の場合、別のエラーが発生する可能性があると考えているためです。)