Skip to main content
Inspiring
December 4, 2017
Question

addChild, removeChild problem

  • December 4, 2017
  • 5 replies
  • 623 views

Hi,

I'm trying to get two separate swipe galleries to work.

I have one movie clip (home_menu) which contains two buttons (button_1 and button_2).

I want to open each gallery in another movie clip (container_mc)  on the main timeline. This is located on the bottom layer because I need other objects to sit above the two galleries.

So when I click on button_1 I want it to load gallery1 and unload gallery2 and vice versa with button 2.

But I'm getting the following error message. I've Googled it and searched forums but I've obviously created another unique problem for myself which is becoming something I'm specialising in it seems:

"Call to a possibly undefined method addChild through a reference with static type flash.display:SimpleButton."

This is how I'm causing that error:

import flash.display.MovieClip;

import flash.display.Sprite;

var gallery1:MovieClip=new gallery_items1;

var gallery2:MovieClip=new gallery_items2;

home_menu.button_1.addEventListener(MouseEvent.CLICK, fl_addGallery1);

function fl_addGallery1(event:MouseEvent):void

{

container_mc.addChild(gallery1);

gallery1.x= 28;

gallery1.y= 45;

container_mc.removeChild(gallery2);

}

home_menu.button_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

{

container_mc.addChild(gallery2);

gallery2.x= 28;

gallery2.y= 45;

container_mc.removeChild(gallery1);

}

Any advice truly appreciated.

This topic has been closed for replies.

5 replies

Inspiring
December 8, 2017

Brilliant!

Thank you.

kglad
Community Expert
Community Expert
December 8, 2017

you're welcome.

Inspiring
December 6, 2017

This line:

root.holder_mc.addChild(gallery1);

Thanks

kglad
Community Expert
Community Expert
December 6, 2017

use

MovieClip(root).holder_mc.addChild(gallery1);

Inspiring
December 6, 2017

Well spotted! I had mistakenly created container_mc as a button.

So I've rectified that. Renamed it to holder_mc throughout (not sure why??) but the same error is occurring!?

ie: 1119: Access of possibly undefined property holder_mc through a reference with static type flash.display:DisplayObject.

I thought you had the solution there but unfortunately not.

Thanks anyway.

kglad
Community Expert
Community Expert
December 6, 2017

what line of code is triggering the error message?

Ned Murphy
Legend
December 5, 2017

Is container_mc really an mc, or is it a button - check in the Properties panel?  Buttons have limited properties/methods.

kglad
Community Expert
Community Expert
December 4, 2017

click file>publish settings>and tick 'permit debugging'.  retest.

the frame and problematic line number will be in the error message allowing you to pinpoint the problem. (though if the problem is caused by the code you showed, you should already know the problematic line(s) of code.)