Skip to main content
Participating Frequently
December 12, 2015
Answered

RemoveChild on buttons to remove movieclips

  • December 12, 2015
  • 1 reply
  • 2712 views

Hello,

I have been going crazy trying to make my little flash site to work. I have used the removeChild script to remove movieclips on the stage when you click a button. When I test it the first button clicked loads the appropriate movieclip and unloads any movie that was playing (in this case it is the home content) but then none of the other buttons work after including the first button that previously worked. Its like the removechild removes it completely. My script is below and any help woul;d be so very much appreciated:

b1.addEventListener(MouseEvent.CLICK, playhomebutton);

function playhomebutton(e: MouseEvent): void {

homecontent.play();

}

b1.addEventListener(MouseEvent.CLICK, removeGallery1);

function removeGallery1(event:MouseEvent):void{

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

b1.addEventListener(MouseEvent.CLICK, removevideo1);

function removevideo1(event:MouseEvent):void{

if (video.parent)

    video.parent.removeChild(video);

}

b1.addEventListener(MouseEvent.CLICK, removematerials1);

function removematerials1(event:MouseEvent):void{

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

b2.addEventListener(MouseEvent.CLICK, playgallerybutton);

function playgallerybutton(e: MouseEvent): void {

    gallery.play();

}

b2.addEventListener(MouseEvent.CLICK, removeHome);

function removeHome(event:MouseEvent):void{

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

b2.addEventListener(MouseEvent.CLICK, removevideo2);

function removevideo2(event:MouseEvent):void{

if (video.parent)

    video.parent.removeChild(video);

}

b2.addEventListener(MouseEvent.CLICK, removematerials2);

function removematerials2(event:MouseEvent):void{

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

b3.addEventListener(MouseEvent.CLICK, playvideobutton);

function playvideobutton(e: MouseEvent): void {

video.play();

}

b3.addEventListener(MouseEvent.CLICK, removeHome3);

function removeHome3(event:MouseEvent):void{

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

b3.addEventListener(MouseEvent.CLICK, removeGallery3);

function removeGallery3(event:MouseEvent):void{

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

b3.addEventListener(MouseEvent.CLICK, removematerials3);

function removematerials3(event:MouseEvent):void{

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

b5.addEventListener(MouseEvent.CLICK, playmaterialbutton);

function playmaterialbutton(e: MouseEvent): void {

materialsmovie.play();

}

b5.addEventListener(MouseEvent.CLICK, removeHome5);

function removeHome5(event:MouseEvent):void{

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

b5.addEventListener(MouseEvent.CLICK, removeGallery5);

function removeGallery5(event:MouseEvent):void{

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

b5.addEventListener(MouseEvent.CLICK, removevideo5);

function removevideo5(event:MouseEvent):void{

if (video.parent)

    video.parent.removeChild(video);

}

This topic has been closed for replies.
Correct answer kglad

yes, each click generates a new error.


here's what you should have:  http://www.kglad.com/Files/forums/test5.fla

compare it to what you do have.

1 reply

kglad
Community Expert
Community Expert
December 12, 2015

never nest named functions

b1.addEventListener(MouseEvent.CLICK, playhomebutton);

function playhomebutton(e: MouseEvent): void {

homecontent.play();

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

if (video.parent)

    video.parent.removeChild(video);

}

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

}

b2.addEventListener(MouseEvent.CLICK, playgallerybutton);

function playgallerybutton(e: MouseEvent): void {

    gallery.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

if (video.parent)

    video.parent.removeChild(video);

}

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

}

b3.addEventListener(MouseEvent.CLICK, playvideobutton);

function playvideobutton(e: MouseEvent): void {

video.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

}

b5.addEventListener(MouseEvent.CLICK, playmaterialbutton);

function playmaterialbutton(e: MouseEvent): void {

materialsmovie.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

if (video.parent)

    video.parent.removeChild(video);

}

}

[moved from Adobe Creative Cloud to ActionScript 3]

p.s. post actionscript problems in this forum, not the cc forum.

amycctfaAuthor
Participating Frequently
December 12, 2015

Thanks so much for getting back so quickly and sorry about posting in the wrong spot

I tried out your code. It seems to play all of the movieclips at one time whereas the previous code would load on click the appropriate movie once and unload once but then not again.

Not sure if you could take a look at it?

https://www.dropbox.com/s/9jr7eg5aegrcpkh/syl.zip?dl=0

amycctfaAuthor
Participating Frequently
December 13, 2015

read the comments.  you have all 'out' and 'over' frame labels to all your movieclip buttons.


If you enter into the movieclips 'b1, b2, b3, b4, b5' the time line has the two labels over/out as in the screenshot. Was that not how I was suppose to do it? (the actions are just stop();)