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

animating all instances of movieclip

New Here ,
Sep 18, 2017 Sep 18, 2017

Copy link to clipboard

Copied

I have a frame that has several instances of a movieclip. Each of those instances are named, but I have a button that needs to trigger ALL instances to animate simultaneously.

My code is currently looking like this, where "allInstances" is the clip I'm trying to animate. If that is a specific instance name, it works, but I need to have multiples, and using the original movieClip name doesn't work.

this.exampleBtn.addEventListener("click", doTheThing.bind(this));

function doTheThing()

{

this.parent.parent.allInstances.play("activateIt");

}

Not expecting anyone to write my code for me, but any hints in the right direction would be appreciated.

Thanks!

TOPICS
ActionScript

Views

974

Translate

Translate

Report

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 , Sep 18, 2017 Sep 18, 2017

If you set each one playing one after another, they won't start playing instantly. Also I don't think play("frame label") would work.

To play three movie clips at the same time, and from a frame label of "activateI", and the three of them are in the button's parent's parent, you would do this:

this.exampleBtn.addEventListener("click", doTheThing.bind(this)); 

 

function doTheThing() { 

   this.parent.parent.mc1.gotoAndPlay("activateIt");  

   this.parent.parent.mc2.gotoAndPlay("activateIt"); 

   t

...

Votes

Translate

Translate
LEGEND ,
Sep 18, 2017 Sep 18, 2017

Copy link to clipboard

Copied

If you set each one playing one after another, they won't start playing instantly. Also I don't think play("frame label") would work.

To play three movie clips at the same time, and from a frame label of "activateI", and the three of them are in the button's parent's parent, you would do this:

this.exampleBtn.addEventListener("click", doTheThing.bind(this)); 

 

function doTheThing() { 

   this.parent.parent.mc1.gotoAndPlay("activateIt");  

   this.parent.parent.mc2.gotoAndPlay("activateIt"); 

   this.parent.parent.mc3.gotoAndPlay("activateIt"); 

If you want a lot of copies of the same movieclip to play at the same time you could have a listener in the movieclip itself. For example, in the movieclip that is in the library, have this in frame 1:

stage.addEventListener("doactivate",activatenow.bind(this));

this.stop();

function activatenow(){

  this.gotoAndPlay("activateIt");

}

then change your button script to:

this.exampleBtn.addEventListener("click", doTheThing.bind(this)); 

 

function doTheThing() { 

stage.dispatchEvent("doactivate");

}

I just tried it, and it works well, and has the advantage that it doesn't matter where the button and movieclips are in the hierarchy. Try my test here (click the circle):

playnow

Votes

Translate

Translate

Report

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 ,
Sep 18, 2017 Sep 18, 2017

Copy link to clipboard

Copied

thanks for your response. I was trying to avoid playing them all by name individually, as I'm trying to have them be very reusable. i have other frames with a very similar setup, but the number of movie clips varies. I was hoping for some sort of array type approach, or some naming convention where I can target them all in one shot. That being said, I'll mess around with your second suggestion.  Thanks!

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

You could try something like this.

In frame 1 of the instanced movieClip you want to animate:

stop();

stage.addEventListener("PLAY", doPlay);

function doPlay(e:Event):void

{

     gotoAndPlay(2);

}

And then this on the main timeline - I have a shape with the instance name of 'btn'.

btn.addEventListener(MouseEvent.CLICK, doPlay);

function doPlay(e:MouseEvent):void

{

     stage.dispatchEvent(new Event("PLAY"));

}

Votes

Translate

Translate

Report

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 ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

dmennenoh

This question was about HTML5 Canvas, and your idea is a good one for AS3, but it's also the same as my second suggestion.

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

Essentially the same, I just got rid of the 'this' and 'bind'... which are not needed.

Votes

Translate

Translate

Report

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 ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

The bind(this) is needed in the dispatch line, though not in the movieclip's function. It's only there because I copied his lines.

The main difference with your version is the use of typed variables, and static strings, neither of which exist in HTML5 Canvas.

Votes

Translate

Translate

Report

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
Enthusiast ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

LATEST

Yeah, sorry, I missed the part about it being for HTML5.

Votes

Translate

Translate

Report

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 ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

Second option worked great, Colin. It never occurred to me to have a listener in a different place as the object that will be clicked, but this worked beautifully. Thanks!

Votes

Translate

Translate

Report

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