当按钮悬停在屏幕上时,我使用setChildIndex将按钮移动到屏幕的前面,但我创建了一个“后退”按钮,这样电影就可以在时间轴上向后移动几帧来查看上一个屏幕。我的问题是,当我使用后退按钮返回到时间线中的那个点时,setChildIndex按钮仍然留在屏幕上。下面的脚本显示了我拥有的按钮,然后是back按钮。如何才能使后退按钮同时删除所有按钮?是否存在类似于“如果包含btn1、btn2等..删除子项”之类的东西?
stop();
//campaign
campaign_btn.addEventListener(MouseEvent.ROLL_OVER, roll1);
function roll1(event:MouseEvent):void {
setChildIndex(campaign_btn, numChildren-1);
};
//survey
survey_btn.addEventListener(MouseEvent.ROLL_OVER, roll2);
function roll2(event:MouseEvent):void {
setChildIndex(survey_btn, numChildren-1);
};
//project
project_btn.addEventListener(MouseEvent.ROLL_OVER, roll3);
function roll3(event:MouseEvent):void {
setChildIndex(project_btn, numChildren-1);
};
//filestore
filestore_btn.addEventListener(MouseEvent.ROLL_OVER, roll4);
function roll4(event:MouseEvent):void {
setChildIndex(filestore_btn, numChildren-1);
};
//website
website_btn.addEventListener(MouseEvent.ROLL_OVER, roll5);
function roll5(event:MouseEvent):void {
setChildIndex(website_btn, numChildren-1);
};
//forms
forms_btn.addEventListener(MouseEvent.ROLL_OVER, roll6);
function roll6(event:MouseEvent):void {
setChildIndex(forms_btn, numChildren-1);
};
//invoice
invoice_btn.addEventListener(MouseEvent.ROLL_OVER, roll7);
function roll7(event:MouseEvent):void {
setChildIndex(invoice_btn, numChildren-1);
};
//CRM
CRM_btn.addEventListener(MouseEvent.ROLL_OVER, roll8);
function roll8(event:MouseEvent):void {
setChildIndex(CRM_btn, numChildren-1);
};
//--------------------------back button------------------------------
back_btn.addEventListener(MouseEvent.CLICK, buttonClick1);
function buttonClick1(event:MouseEvent):void
{
if(contains(campaign_btn))
{
removeChild(campaign_btn);
}
gotoAndPlay(1124);
}
发布于 2011-02-28 23:04:13
如果我没记错,我可能错了,因为我已经有一段时间没有使用可怕的时间线了,用任何子函数修改的时间线对象不再是正常时间线流的一部分。所以当离开一个框架时,它们不会消失,你必须手动处理它。
在后退按钮的onClick事件处理程序中添加删除对象,或添加到每个对象中:
objectToBeRemoved.addEventListener(Event.ENTER_FRAME, killer);
function killer(e:Event):void{
if (currentFrame != 11)
removeChild(objectToBeRemoved)
}
但这并不是真正优化的解决方案。可能无法开箱工作,我太困了,无法更好地集中精力。
https://stackoverflow.com/questions/5148484
复制相似问题