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

RemoveChild on buttons to remove movieclips

New Here ,
Dec 12, 2015 Dec 12, 2015

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

}

TOPICS
ActionScript
2.2K
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

Community Expert , Dec 14, 2015 Dec 14, 2015

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

compare it to what you do have.

Translate
Community Expert ,
Dec 12, 2015 Dec 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.

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 ,
Dec 12, 2015 Dec 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

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

each button plays a movie and removes the other movies.

if you see something else, you have code elsewhere causing that.  if you want something else, explain what you want.

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 ,
Dec 12, 2015 Dec 12, 2015

This is the complete script:

stop();

b1.addEventListener(MouseEvent.ROLL_OVER, a);

function a(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("a");

}

b1.addEventListener(MouseEvent.ROLL_OUT, b);

function b(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("b");

}

b2.addEventListener(MouseEvent.ROLL_OVER, c);

function c(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("c");

}

b2.addEventListener(MouseEvent.ROLL_OUT, d);

function d(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("d");

}

b3.addEventListener(MouseEvent.ROLL_OVER, e);

function e(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("e");

}

b3.addEventListener(MouseEvent.ROLL_OUT, f);

function f(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("f");

}

b4.addEventListener(MouseEvent.ROLL_OVER, g);

function g(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("g");

}

b4.addEventListener(MouseEvent.ROLL_OUT, h);

function h(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("h");

}

b5.addEventListener(MouseEvent.ROLL_OVER, i);

function i(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("i");

}

b5.addEventListener(MouseEvent.ROLL_OUT, j);

function j(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("j");

}

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

}

}

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

that's not the code i suggested.

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 ,
Dec 12, 2015 Dec 12, 2015

The first part of the code plays a roll over movieclip for my buttons:

b1.addEventListener(MouseEvent.ROLL_OVER, a);

function a(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("a");

}

b1.addEventListener(MouseEvent.ROLL_OUT, b);

function b(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("b");

}

b2.addEventListener(MouseEvent.ROLL_OVER, c);

function c(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("c");

}

b2.addEventListener(MouseEvent.ROLL_OUT, d);

function d(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("d");

}

b3.addEventListener(MouseEvent.ROLL_OVER, e);

function e(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("e");

}

b3.addEventListener(MouseEvent.ROLL_OUT, f);

function f(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("f");

}

 

b4.addEventListener(MouseEvent.ROLL_OVER, g);

function g(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("g");

}

b4.addEventListener(MouseEvent.ROLL_OUT, h);

function h(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("h");

}

b5.addEventListener(MouseEvent.ROLL_OVER, i);

function i(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("i");

}

b5.addEventListener(MouseEvent.ROLL_OUT, j);

function j(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("j");

}

The second part (your code) should load movies that would be the content for the site:

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

}

}

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 ,
Dec 12, 2015 Dec 12, 2015

Also if I remove all of AS3 for the rollover movies and just use your code, all movie clips play simultaneously despite having stops.  

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

to 'add' the movieclips before they play, use:

b1.addEventListener(MouseEvent.CLICK, playhomebutton);

function playhomebutton(e: MouseEvent): void {

addChild(homecontent);

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 {

addChild(gallery);

    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 {

addChild(video);

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 {

addChild(materialsmovie);

materialsmovie.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

if (gallery.parent)

    gallery.parent.removeChild(gallery);

}

if (video.parent)

    video.parent.removeChild(video);

}

}

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 ,
Dec 12, 2015 Dec 12, 2015

ok thanks. I am going to spend some more time seeing if I can fix it with your suggested code. For the moment, I'm still dealing with all of the movieclips playing on the stage at the same time. The buttons don't activate the movies or change them from all playing at once either.

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

you need stop() on the first frame of all your button movieclips (that have those rollover/rollout listeners).

and you need stop() on the first frame of all your movieclips that are added/played in the code.

and if you see any compiler errors those need to be fixed.

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 ,
Dec 12, 2015 Dec 12, 2015

ok so the stop() was on all the movieclips previously but I have worked on the compiler errors and removed some closing curly brackets from your code (only cause of compiler errors) and now is working with just a few errors. The home loads first correctly and then you click on b2 and it loads correctly and unloads b1. The problem arises when I click on the b3 as it doesn't remove the movieclip from b2. Then clicking on b5 adds the movieclip correclty but isn't removing the previous 2 (b2 and b3). We are getting there though Thanks so much for your patience. I'm pretty new to AS3 and perhaps am not explaining myself very well. Here is the code(I have no idea why the errors are coming up on the closing brackets but removed it gives no errors):

b1.addEventListener(MouseEvent.CLICK, playhomebutton);

function playhomebutton(e: MouseEvent): void {

addChild(homecontent);

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 {

addChild(gallery);

    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 {

addChild(video);

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 {

addChild(materialsmovie);

materialsmovie.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

}

if (gallery.parent)

    gallery.parent.removeChild(gallery);

if (video.parent)

    video.parent.removeChild(video);

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

let's simplify your code so it's easier to debug.  first rename b5 to b4 so you have b1,b2,b3,b4. (it doesn't make much sense to have b1,b2,b3,b5.)

then replace all the non-rollover,rollout code with:

var mcA:Array = [homecontent,gallery,video,materialsmovie];
for(var i:int=0;i<mcA.length;i++){
this['b'+(i+1)].ivar=i+1;
this['b'+(i+1)].addEventListener(MouseEvent.CLICK,bF);
}

function bF(e:MouseEvent):void{

removeAllF();

addChild(mcA[MovieClip(e.currentTarget).ivar-1];

}

function removeAllF():void{

for(var i:int=0;i<mcA.length;i++){

if(mcA.stage){

mcA.parent.removeChild(mcA);

}

}

}

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 ,
Dec 12, 2015 Dec 12, 2015

I'm getting the below error with this code:

"Scene 1, Layer 'actions', Frame 1, Line 70, Column 13  1151: A conflict exists with definition i in namespace internal."

I also don't understand bF from here ['b'+(i+1)].addEventListener(MouseEvent.CLICK,bF);

Here is the code (including the rollovers) I bolded the error line:

import flash.events.MouseEvent;

stop();

b1.addEventListener(MouseEvent.ROLL_OVER, a);

function a(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("a");

}

b1.addEventListener(MouseEvent.ROLL_OUT, b);

function b(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("b");

}

b2.addEventListener(MouseEvent.ROLL_OVER, c);

function c(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("c");

}

b2.addEventListener(MouseEvent.ROLL_OUT, d);

function d(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("d");

}

b3.addEventListener(MouseEvent.ROLL_OVER, e);

function e(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("e");

}

b3.addEventListener(MouseEvent.ROLL_OUT, f);

function f(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("f");

}

b4.addEventListener(MouseEvent.ROLL_OVER, i);

function i(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("i");

}

b4.addEventListener(MouseEvent.ROLL_OUT, j);

function j(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("j");

}

b5.addEventListener(MouseEvent.ROLL_OVER, g);

function g(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("g");

}

b5.addEventListener(MouseEvent.ROLL_OUT, h);

function h(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("h");

}

var mcA:Array = [homecontent,gallery,video,materialsmovie];

for(var i:int=0;i<mcA.length;i++){

this['b'+(i+1)].ivar=i+1;

this['b'+(i+1)].addEventListener(MouseEvent.CLICK,bF);

}

function bF(e:MouseEvent):void{

removeAllF();

addChild(mcA[MovieClip(e.currentTarget).ivar-1]);

}

function removeAllF():void{

for(var i:int=0;i<mcA.length;i++){

if(mcA.stage){

mcA.parent.removeChild(mcA);

  }

  }

  }

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

replace that bolded code with:

for(i=0;i<mcA.length;i++){

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 ,
Dec 12, 2015 Dec 12, 2015

That causes quite a few more errors:

Scene 1, Layer 'actions', Frame 1, Line 70, Column 9    1178: Attempted access of inaccessible property i through a reference with static type uncleearlforum1_fla:MainTimeline.

Scene 1, Layer 'actions', Frame 1, Line 70, Column 11    1168: Illegal assignment to function i.

Scene 1, Layer 'actions', Frame 1, Line 70, Column 27    1107: Increment operand is invalid.

Scene 1, Layer 'actions', Frame 1, Line 70, Column 26    1067: Implicit coercion of a value of type Function to an unrelated type Number.

Scene 1, Layer 'actions', Frame 1, Line 70, Column 13    1176: Comparison between a value with static type Function and a possibly unrelated type uint.

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
Community Expert ,
Dec 12, 2015 Dec 12, 2015

copy and paste the code you're using.

(actually, there's code in your project that you're not showing or you wouldn't get the namespace conflict.)

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 ,
Dec 13, 2015 Dec 13, 2015

This is the code inside the movie clip gallery:

stop();

btn1.addEventListener(MouseEvent.CLICK, play1);

function play1(event: MouseEvent): void {

gotoAndStop("birds")

}

btn2.addEventListener(MouseEvent.CLICK, play2);

function play2(event: MouseEvent): void {

gotoAndStop("shark")

}

btn3.addEventListener(MouseEvent.CLICK, play3);

function play3(event: MouseEvent): void {

gotoAndStop("city")

}

btn4.addEventListener(MouseEvent.CLICK, play4);

function play4(event: MouseEvent): void {

gotoAndStop("car")

}

This is the code inside my logo movieclip (tried deleting it and it makes no difference)

function playAnimation(event:MouseEvent):void

{

    waterwheel.play();

}

And this is the main code that we have been working on together (other than stop() there isn't anything else)


import flash.events.MouseEvent;

stop();

b1.addEventListener(MouseEvent.ROLL_OVER, a);

function a(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("a");

}

b1.addEventListener(MouseEvent.ROLL_OUT, b);

function b(e: MouseEvent): void {

    MovieClip(b1).gotoAndPlay("b");

}

b2.addEventListener(MouseEvent.ROLL_OVER, c);

function c(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("c");

}

b2.addEventListener(MouseEvent.ROLL_OUT, d);

function d(e: MouseEvent): void {

    MovieClip(b2).gotoAndPlay("d");

}

b3.addEventListener(MouseEvent.ROLL_OVER, e);

function e(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("e");

}

b3.addEventListener(MouseEvent.ROLL_OUT, f);

function f(e: MouseEvent): void {

    MovieClip(b3).gotoAndPlay("f");

}

b4.addEventListener(MouseEvent.ROLL_OVER, i);

function i(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("i");

}

b4.addEventListener(MouseEvent.ROLL_OUT, j);

function j(e: MouseEvent): void {

    MovieClip(b4).gotoAndPlay("j");

}

b5.addEventListener(MouseEvent.ROLL_OVER, g);

function g(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("g");

}

b5.addEventListener(MouseEvent.ROLL_OUT, h);

function h(e: MouseEvent): void {

    MovieClip(b5).gotoAndPlay("h");

}

    var mcA:Array = [homecontent,gallery,video,materialsmovie];

    for(i=0;i<mcA.length;i++){

    this['b'+(i+1)].ivar=i+1;

    this['b'+(i+1)].addEventListener(MouseEvent.CLICK,bF);

    }

    function bF(e:MouseEvent):void{

    removeAllF();

    addChild(mcA[MovieClip(e.currentTarget).ivar-1]);

    }

    function removeAllF():void{

    for(var i:int=0;i<mcA.length;i++){

    if(mcA.stage){

    mcA.parent.removeChild(mcA);

    }

    }

    }

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 ,
Dec 13, 2015 Dec 13, 2015

So I went back to your first suggestion because so far it was working better than the other solutions. I noticed that the closing curly bracket wasn't in the right spot for each function so I added to include all of the movies as it was previously just closing after the home. On first test it works great, it's glitchy however because when you start to navigate the buttons (other than home which does what it is suppose to do) you need to click the button twice for it to load. but the movies are being removed and load at least!

b1.addEventListener(MouseEvent.CLICK, playhomebutton);

function playhomebutton(e: MouseEvent): void {

addChild(homecontent);

homecontent.play();

if (gallery.parent)

    gallery.parent.removeChild(gallery);

if (video.parent)

    video.parent.removeChild(video);

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

if (contactmovie.parent)

    contactmovie.parent.removeChild(contactmovie);

}

b2.addEventListener(MouseEvent.CLICK, playgallerybutton);

function playgallerybutton(e: MouseEvent): void {

addChild(gallery);

    gallery.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

if (video.parent)

    video.parent.removeChild(video);

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

if (contactmovie.parent)

    contactmovie.parent.removeChild(contactmovie);

}

b3.addEventListener(MouseEvent.CLICK, playvideobutton);

function playvideobutton(e: MouseEvent): void {

addChild(video);

video.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

if (gallery.parent)

    gallery.parent.removeChild(gallery);

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

if (contactmovie.parent)

    contactmovie.parent.removeChild(contactmovie);

}

b4.addEventListener(MouseEvent.CLICK, playcontactbutton);

function playcontactbutton(e: MouseEvent): void {

addChild(contactmovie);

contactmovie.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

if (gallery.parent)

    gallery.parent.removeChild(gallery);

if (video.parent)

    video.parent.removeChild(video);

if (materialsmovie.parent)

    materialsmovie.parent.removeChild(materialsmovie);

}

b5.addEventListener(MouseEvent.CLICK, playmaterialbutton);

function playmaterialbutton(e: MouseEvent): void {

addChild(materialsmovie);

materialsmovie.play();

if (homecontent.parent)

    homecontent.parent.removeChild(homecontent);

if (gallery.parent)

    gallery.parent.removeChild(gallery);

if (video.parent)

    video.parent.removeChild(video);

if (contactmovie.parent)

    contactmovie.parent.removeChild(contactmovie);

}

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
Community Expert ,
Dec 13, 2015 Dec 13, 2015

you have a function named i().

that's problematic.

change it to something else like iF.  likewise for your other single letter named functions.

or you could change the for loop variable, but it would be better to use standard coding conventions and change those function names.

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
Community Expert ,
Dec 13, 2015 Dec 13, 2015

actually, you may as well fix all those rollover/rollouts too.  this replaces all your movieclip button code

var mcA:Array = [homecontent,gallery,video,materialsmovie];
for(var i:int=0;i<mcA.length;i++){
this['b'+(i+1)].ivar=i+1;
this['b'+(i+1)].addEventListener(MouseEvent.ROLL_OVER,overF);
this['b'+(i+1)].addEventListener(MouseEvent.ROLL_OUT,outF);
this['b'+(i+1)].addEventListener(MouseEvent.CLICK,bF);
}

function overF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('over');  // label this frame in each of your movieclip buttons

}

function overF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('out');  // label this frame in each of your movieclip buttons

}

function bF(e:MouseEvent):void{

removeAllF();

addChild(mcA[MovieClip(e.currentTarget).ivar-1]);

}

function removeAllF():void{

for(var i:int=0;i<mcA.length;i++){

if(mcA.stage){

mcA.parent.removeChild(mcA);

}

}

}

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 ,
Dec 13, 2015 Dec 13, 2015

ok so I relabeled my roll over / roll out and replaced all the code with the code above. I get this error (and all movies are playing simultaneously) :

Scene 1, Layer 'actions', Frame 1, Line 11, Column 58    1120: Access of undefined property outF.

Scene 1, Layer 'actions', Frame 1, Line 27, Column 15    1120: Access of undefined property e.

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
Community Expert ,
Dec 13, 2015 Dec 13, 2015

function overF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('over');  // label this frame in each of your movieclip buttons

}

function overF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('out');  // label this frame in each of your movieclip buttons

}

function bF(e:MouseEvent):void{

removeAllF();

addChild(mcA[MovieClip(e.currentTarget).ivar-1]);

}

function removeAllF():void{

for(var i:int=0;i<mcA.length;i++){

if(mcA.stage){

mcA.parent.removeChild(mcA);

}

}

}

should be:

function overF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('over');  // label this frame in each of your movieclip buttons

}

function outF(e:MouseEvent):void{

MovieClip(e.currentTarget).gotoAndPlay('out');  // label this frame in each of your movieclip buttons

}

function bF(e:MouseEvent):void{

removeAllF();

addChild(mcA[MovieClip(e.currentTarget).ivar-1]);

}

function removeAllF():void{

for(var i:int=0;i<mcA.length;i++){

if(mcA.stage){

mcA.parent.removeChild(mcA);

}

}

}

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 ,
Dec 13, 2015 Dec 13, 2015

Errors that come up: (good news is that home loads and all movies aren't playing at once now.)

ArgumentError: Error #2109: Frame label over not found in scene over.

    at flash.display::MovieClip/gotoAndPlay()

    at uncleearlforum_finaloldcodewithlatestsuggestioni__fla::MainTimeline/overF()

ArgumentError: Error #2109: Frame label out not found in scene out.

    at flash.display::MovieClip/gotoAndPlay()

    at uncleearlforum_finaloldcodewithlatestsuggestioni__fla::MainTimeline/outF()

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
Community Expert ,
Dec 13, 2015 Dec 13, 2015

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

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