2013-05-18 40 views
0

我想擺脫一個對象,但它拋出的錯誤不完全確定問題是什麼。ArgumentError:錯誤#2025:提供的DisplayObject必須是調用者的孩子

的錯誤我得到:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. 
    at flash.display::DisplayObjectContainer/removeChild() 
    at SchoolBook_Final_fla::MainTimeline/garbage_cl_2()[SchoolBook_Final_fla.MainTimeline::frame2:98] 
    at Function/SchoolBook_Final_fla:MainTimeline/choice_play_ev/SchoolBook_Final_fla:play_target()[SchoolBook_Final_fla.MainTimeline::frame2:81] 

我的代碼:

import flash.display.Sprite; 
import flash.ui.Mouse; 
import flash.events.Event; 

var week_pick:Weekday_Choice = new Weekday_Choice(); 
var weekdayArray: Array = new Array(); 
var monday:Mon_D_but = new Mon_D_but(); 
var tuesday:Tues_D_but = new Tues_D_but(); 
var wednesday:Wed_D_but = new Wed_D_but(); 
var thursday:Thurs_D_but = new Thurs_D_but(); 
var friday:Fri_D_but = new Fri_D_but(); 
var choice_play: Array = new Array(); 

choice_play.push(monday, tuesday, wednesday, thursday, friday); 
//Adding Week Pick 
addChild(week_pick); 
//Placing all the Buttons 
choice_play[0].x = 73.1; 
choice_play[0].y = 316.75; 

choice_play[1].x = 251.9; 
choice_play[1].y = 278.35; 

choice_play[2].x = 399.95; 
choice_play[2].y = 375.85; 

choice_play[3].x = 345.2; 
choice_play[3].y = 602.4; 

choice_play[4].x = 80.15; 
choice_play[4].y = 603.05; 

for (var a = 0; a < choice_play.length; a++) 
{ 
    //Asking all the Buttons to stop 
    choice_play[a].alpha = 0; 
    choice_play[a].stop(); 
} 
//Event for the week pick to start 
week_pick.addEventListener(Event.ENTER_FRAME, moveon); 
//Getting the function started 
function moveon(event:Event) 
{ 
    if (week_pick.currentFrame == 103) 
    { 

     week_pick.stop(); 
     for (a = 0; a < choice_play.length; a++) 
     { 
      addChild(choice_play [a]); 

     } 
     //adding an Event listener for clicking the buttons 
     this.addEventListener(MouseEvent.CLICK,choice_play_ev); 


    } 
} 

function choice_play_ev(play_event: MouseEvent) 
{ 
    trace ("Event gets added"); 
    trace (play_event.target); 
    //Work if the target isn't the background clip 
    if (play_event.target != week_pick) 
    { 
     trace (play_event.target); 
     //Turn back the opacity for what ever was cliked on 
     play_event.target.alpha = 1; 
     //asking the choice to play it's animation 
     play_event.target.addEventListener(Event.ENTER_FRAME, play_target); 
     this.removeEventListener(MouseEvent.CLICK,choice_play_ev); 
     function play_target(play_event_cl:Event) 
     { 

      play_event_cl.target.play(); 
      if (play_event_cl.target.currentFrame == 15) 
      { 
       //remove the [;ace event listener once the animation is done 
       play_event.target.removeEventListener(Event.ENTER_FRAME, play_target); 
       garbage_cl_2(); 
      } 
     } 
    } 
} 

function garbage_cl_2() 
{ 

    trace("it works"); 
    for (a = 0; a < choice_play.length; a++) 
    { 
     //remove all the choices from the display list 
     removeChild(choice_play [a]); 
    } 
    //Remove all the choices from the array for better garbage cleaning 
    choice_play.splice(0, choice_play.length); 
    removeChild(week_pick); 
    week_pick.removeEventListener(Event.ENTER_FRAME, moveon); 
    trace("The choice_play is " + choice_play.length); 
    gotoAndStop(3); 

} 

有人可以幫我這個好嗎?還要告訴我爲什麼會拋出錯誤?

回答

0

你的garbage_cl_2()功能

for (a = 0; a < choice_play.length; a++) 
{ 
    //remove all the choices from the display list 
    removeChild(choice_play [a]); 
} 

和/或呼叫removeChild(week_pick);嘗試內環路刪除MovieClip這不是當前MovieClip對象的直接子。當前剪輯是其時間軸中包含代碼爲garbage_cl_2()函數的幀的剪輯。該removeChild()方法只能去除DisplayObjectContainer實例的直接子 - 如果當前剪輯的不是這些剪輯的直接父,你需要指定,像這樣的父剪輯:

parentclip.removeChild (...); 
相關問題