我试图在数组内添加一个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