我使用setChildIndex将按钮悬停在屏幕的正面,但是我创建了一个“后退”按钮,这样它就可以在时间轴中将电影带回几帧以查看上一个屏幕。我的问题是,当我使用后退按钮返回时间轴中的那个点时,setChildIndex按钮仍然保留在屏幕上。我下面的脚本显示了我有的按钮,然后是后退按钮。如何才能使后退按钮同时删除所有按钮?有没有像“如果包含btn1,btn2,ect ..删除孩子”之类的东西?
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);
}
答案 0 :(得分:1)
如果我没记错,我可能错了,因为我没有使用可怕的时间轴一段时间,使用任何子函数修改的时间轴对象不再是正常时间轴流程的一部分。因此,当离开框架时它们不会消失,你必须手动处理它。
添加后退按钮的onClick事件处理程序删除对象,或添加到每个对象:
objectToBeRemoved.addEventListener(Event.ENTER_FRAME, killer);
function killer(e:Event):void{
if (currentFrame != 11)
removeChild(objectToBeRemoved)
}
但它并不是真正优化的解决方案。可能没有开箱即用,我太困了,无法集中注意力。