我試圖在數組內添加一個MovieClip實例。 House類內部是一個名爲HouseObjects的屬性。在這個數組中,我創建了一個Comp和一個Light類。動畫片段通過鏈接動態放置在舞臺上。影片剪輯也可以充當「切換按鈕」。如果按鈕狀態爲ON,則值爲1.如果按鈕狀態爲OFF,則值爲0.將動畫片段的動態實例添加到數組
如果值爲1,我試圖在onList Array中添加MovieClip實例。在該數組內部將有所有按鈕狀態爲ON的實例。
我創建了一個名爲objSelect的屬性。
var objSelect:Object;
該變量包含currentTarget選定。我試圖將它傳遞給function trackItems
,以便根據按鈕狀態在onList數組中按下/彈出它。
我收到有關此錯誤的信息: onList.pop(objSelect); 參數的數量不正確。預計不超過0.1
public class House extends MovieClip
{
var HouseObjects:Array = new Array();
var onList:Array = []; // instances added to this array that have a bstatus ON
var power:int; // holds value of individual House Objects
var bstate:int; // 0 or 1 (ON or OFF)
var bstatus:int;
var userInput:int; // stores user data (of selected data);
//holds value of e.currentTarget.power
var currentPower:int; // stores current power
var objSelect:Object;
public function House()
{
// Instances are MovieClip "toggle buttons"
HouseObjects[0] = new Comp(); // creates instance of Comp
HouseObjects[1] = new Light(); // creates instance of Light
}
function toggleClick(e:MouseEvent) {
// go to appropriate frame
if (e.currentTarget.currentFrame == 2)
{
e.currentTarget.gotoAndStop(3);
e.currentTarget.bstate = 1;
}
if (e.currentTarget.currentFrame == 4)
{
e.currentTarget.gotoAndStop(1);
e.currentTarget.bstate = 0;
}
bstatus = e.currentTarget.bstate;
objName = e.currentTarget.name;
trackItems(objSelect, bstatus);
} // end of function toggle click
function trackItems(objSelect:Object, bstatus:int):void
{
if (bstatus == 0) {
// remove objSelect from Array onList
} else if (bstatus == 1) {
onList.push(objSelect);
//add to Array onList
}
}
// function called when user clicks on update button
function updateStage():void
{
for (var i:int = 0; i<=onList.length;i++) {
addChild(onList[i]);
}
}
}
我想彈出只是從列表的末尾刪除項目。你的意思是推? – akonsu 2010-08-29 20:13:47
@akonsu取決於對象的狀態(開/關) - 我需要將它推入或彈出陣列。如果對象的狀態爲ON - POP(添加到數組),如果OFF - PUSH(移出數組)。 – jc70 2010-08-29 20:18:07