我有按钮将影片剪辑添加到舞台上,当点击其他按钮添加另一个按钮时,它不会消失。我已经看过类似的问题,但没有一个答案对我有用。
btnBlue.addEventListener(MouseEvent.CLICK, fl_MouseOverHandler1);
function fl_MouseOverHandler1(evt: MouseEvent): void {
var ballBlue: BallBlue = new BallBlue;
addChild(ballBlue);
addChildAt(ballBlue, 0);
ballBlue.x = 100; //sets the x position
ballBlue.y = 100; //sets the y position}
function onClick(evt:MouseEvent):void { */to remove clip if one is playing
removeChildAt(0)
}
}
btnRed.addEventListener(MouseEvent.CLICK, fl_MouseOverHandler2);
function fl_MouseOverHandler2(evt: MouseEvent): void {
var ballRed: BallRed = new BallRed;
addChild(ballRed);
addChildAt(ballRed, 0);
ballRed.x = 100; //sets the x position
ballRed.y = 100; //sets the y position}
parent.BallBlue.removeMovieClip();
function onClick(evt:MouseEvent):void { */to remove clip if one is playing
removeChildAt(0)
}
}
答案 0 :(得分:0)
btnBlue.addEventListener(MouseEvent.CLICK, btnBlue_clickHandler);
btnRed.addEventListener(MouseEvent.CLICK, btnRed_clickHandler);
var ballBlue: BallBlue = new BallBlue();
var ballRed: BallRed = new BallRed();
function btnBlue_clickHandler(evt:MouseEvent):void {
removeAllBalls();
addChild(ballBlue);
ballBlue.x = 100; //sets the x position
ballBlue.y = 100; //sets the y position
}
function btnRed_clickHandler(evt:MouseEvent):void {
removeAllBalls();
addChild(ballRed);
ballRed.x = 100; //sets the x position
ballRed.y = 100; //sets the y position
}
function removeAllBalls():void {
if (contains(ballBlue))
{
removeChild(ballBlue);
}
if (contains(ballRed))
{
removeChild(ballRed);
}
}