在舞台上我有三种动画片段 很少有静态动画片段,其名称为:mc1; MC2; mc3 ....他们在舞台上可见 很少有静态movielips“othermc1; othermc2l othermc3 ......而且他们有”visible = false“ 一个正在舞台上移动的电影片段,他的名字是“滑块” 我有功能当mc“slider”与mc1,mc2 ...的其余部分相交时,可以将othermc1,othermc2转换为其他颜色
var alreadyHandled:Boolean = false;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(e:Event):void
{
if(mc1.getRect(this).intersects(slider.getRect(this)))
{
if(!alreadyHandled)
{
show1();
alreadyHandled = true;
}
}
else
{
alreadyHandled = false;
no1();
}
function show1():void
{
othermc1.visible = true;
}
function no1():void
{
othermc2.visible = false;
}
我如何在循环中使用此代码? 谢谢你的帮助
答案 0 :(得分:1)
如果你想循环通过mc1,mc2,mc3,...创建Array
MovieClip
s:
var movieClips:Array = [mc1,mc2,mc3/*,other...*/];
然后使用for
迭代数组元素:
for(var i:int=0; i<movieClips.length; i++){
//do some thing with movieClips[i]
}
此代码可以帮助您:
var mc:Array = [mc1,mc2,mc3/*,...*/];
var omc:Array = [othermc1,othermc2,othermc3/*,other...*/];
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(e:Event):void
{
for(var i:int=0; i<mc.length; i++)
if(mc[i].getRect(this).intersects(slider.getRect(this)))
showMovieClip(i); //or omc[i].visible=true;
else
hideMovieClip(i); //or omc[i].visible=false;
}
function showMovieClip(i:int):void
{
omc[i].visible = true;
}
function hideMovieClip(i:int):void
{
omc[i].visible = false;
}