Arrays 如何在for循环as3中单独访问Movieclips
假设mySaveNewT.data.myNText=20,在for循环中,20个MovieClips(Arrays 如何在for循环as3中单独访问Movieclips,arrays,actionscript-3,flash,for-loop,Arrays,Actionscript 3,Flash,For Loop,假设mySaveNewT.data.myNText=20,在for循环中,20个MovieClips(tbox)填充在舞台上。单击tbox实例时,我想将其可见性更改为false 我如何引用被点击的单个MovieClip,而不必将每个MovieClip的可见性设置为false?(即,如果单击了MC[2]和MC[10],但其余的没有) 如何将其推入阵列中 以下是我的for循环: for (var i: Number = 0; i < mySaveNewT.data.myNText; +
tbox
)填充在舞台上。单击tbox
实例时,我想将其可见性更改为false
MC[2]
和MC[10]
,但其余的没有) for (var i: Number = 0; i < mySaveNewT.data.myNText; ++i) {
newText = new tbox();
newText.x = -220;
newText.y = -513 + i * 69 + 0 * 3.8;
VWD.addChild(newText);
}
for(变量i:Number=0;i
要插入数组,添加单击侦听器并更改可见性,请参见代码注释:
//you need to define an array to store the clips in
var clickedBoxes:Array = []; //this makes a new empty array, same as doing: = new Array();
for (var i: Number = 0; i < mySaveNewT.data.myNText; ++i) {
newText = new tbox();
newText.x = -220;
newText.y = -513 + i * 69 + 0 * 3.8;
VWD.addChild(newText);
newText.addEventListener(MouseEvent.CLICK, clipClickHandler,false,0,true); //now you add a click listener to this clip
}
function clipClickHandler(e:MouseEvent):void {
//e.currentTarget will be a reference to the item that was clicked
MovieClip(e.currentTarget).visible= false; //we wrap e.currentTarget in MovieClip so the compiler knows it has a visible property (casting)
clickedBoxes.push(e.currentTarget);
}
//您需要定义一个数组来存储剪辑
变量点击框:数组=[]//这将生成一个新的空数组,与执行以下操作相同:=new array();
对于(变量i:Number=0;i
要稍后在阵列中循环,请执行以下操作:
for(var index:int=0;index<clickedBoxes.length;index++){
clickedBoxes[index].visible = true; //you may have to cast to avoid a compiler error MovieClip(clickedBoxes[index]).visivle = true;
}
for(var index:int=0;indexThx)对于答案,我有没有办法将准确的MovieClip(e.currentTarget)推送到数组中,因为如果10MC由for循环()填充,并且第二个循环被单击,我需要将其推送到数组中,以便以后可以引用它……例如newText[2].visible=false???那么数组应该是所有被单击的数组?是的,我只是不知道如何从循环中单独引用每个MovieClip…Thxlooks太好了,只是我在for(var i:int=0;iError 1151:与命名空间间隔中的定义i存在冲突。