An error for displayobject--r
I want to create a two buttons for single function and click the same object to make it dissappear in my web. For example, i click "A" and "B", the screen will show "C"object. If I click "C", C will dissappear. I try to make this by removeChild, but it occurs an error when I click "A" and "B" twice
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Function/Page2MC/bothClickedF/page1Click()[Page2MC::frame1:82]
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.ui.Mouse;
var redbtn:MovieClip=new Redbtn();
redbtn.x=321;
redbtn.y=13;
addChild(redbtn);
var bluebtn:MovieClip=new Bluebtn();
bluebtn.x=726;
bluebtn.y=89;
addChild(bluebtn);
var page1:MovieClip=new relationship();
var redBtnClicked:Boolean;
var blueBtnClicked:Boolean;
redbtn.addEventListener(MouseEvent.CLICK, onRedBtnClick);
redbtn.addEventListener(MouseEvent.ROLL_OVER, onRedOver);
redbtn.addEventListener(MouseEvent.ROLL_OUT, onRedOut);
bluebtn.addEventListener(MouseEvent.CLICK, onBlueClick);
bluebtn.addEventListener(MouseEvent.MOUSE_OVER, onBlueOver);
function onRedOver(evt:MouseEvent):void{
redbtn.gotoAndStop(2);
}
function onRedOut(evt:MouseEvent):void{
redbtn.gotoAndStop(3);
}
function onBlueOver(evt:MouseEvent):void{
trace("blueover");
}
function onRedBtnClick(evt:MouseEvent):void{
redBtnClicked=true;
bothClickedF();
}
function onBlueClick(evt:MouseEvent):void{
blueBtnClicked=true;
bothClickedF();
}
function bothClickedF():void{
if (blueBtnClicked&& redBtnClicked){
trace("two buttons are clicked");
addChild(page1);
redBtnClicked=false;
blueBtnClicked=false;
page1.circleC.addEventListener(MouseEvent.CLICK, page1Click);
function page1Click(evt:MouseEvent):void{
removeChild(page1);
}
}
