开发者

Flash:AS3-- setChildIndex problems

I used setChildIndex to move buttons to the front of the screen when they are hovered over, but I have a "back" button created so that it will take the movie a few frames back in the timeline to view a previous screen. My problem is that when I use the back button to return to that point in the timeline, the setChildIndex buttons still remain on the screen. The script that I have below shows that buttons that I have and then the back button. How can I make it so that the back button will remove all of the buttons at the same time? Is there like a "if contains btn1,btn2, ect.. remove child" kind of thing?

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_b开发者_StackOverflow中文版tn.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);
}


If I recall correctly, and I might be wrong as I haven't used the dreaded timeline for some time, timeline objects modified with any of the child functions are no longer part of the normal timeline flow. So when leaving a frame they won't disappear, you have to manually take care of that.

Either add in the back button's onClick event handler removal of the objects, or add to each of the objects:

objectToBeRemoved.addEventListener(Event.ENTER_FRAME, killer);

function killer(e:Event):void{
    if (currentFrame != 11)
        removeChild(objectToBeRemoved)
}

But it's not really optimized solution. Might not work out of the box, I am too sleepy to concentrate better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜