Copy link to clipboard
Copied
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);
}
}
The first thing you should do is move the page1Click button out of that other function so that it stands on its own. Then you should move that event listener assignment for page 1 up with the other event listener assignments so that you don't keep adding it each time that function processes.
Copy link to clipboard
Copied
The first thing you should do is move the page1Click button out of that other function so that it stands on its own. Then you should move that event listener assignment for page 1 up with the other event listener assignments so that you don't keep adding it each time that function processes.
Copy link to clipboard
Copied
oh thank you so much! I got it!
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);
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now