我试图摆脱一个对象,但它抛出一个错误,不完全确定问题是什么。
我得到的错误:
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);
}
有人可以帮我解决这个问题吗?还告诉我为什么会抛出错误?