Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

An error for displayobject--r

New Here ,
Nov 17, 2013 Nov 17, 2013

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);

}

 

                    }

TOPICS
ActionScript
651
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 17, 2013 Nov 17, 2013

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.

Translate
LEGEND ,
Nov 17, 2013 Nov 17, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2013 Nov 17, 2013

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2013 Nov 17, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines