# How do i call an animation before "GoToAndPlay"?

**URL:** <https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060>\
**Category:** flash\
**Created:** [July 3, 2008, 2:06pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060 "2008-07-03T14:06:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![helious](https://avatars.discourse-cdn.com/v4/letter/h/b9e5f3/32.png) [@helious](https://forum.kirupa.com/u/helious)\
**Post date:** [July 3, 2008, 2:06pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/1 "2008-07-03T14:06:16Z")

</div>

I have a question. I think the answer is pretty simple.

On the flash site im working on, i have made a menu of 5 buttons.  
They are all placed on the scene.

Every time the user presses a button i want an animation to be played (Frame 50 to 100), and THEN the script "gotoandplay “Label1”.

How do i do this without copying frame 50 to 100, and pasting them 5 times?

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 3, 2008, 3:13pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/2 "2008-07-03T15:13:39Z")

</div>

if you are using as2 you would do something like so.

this will set the button up to play the animation when it is released.

```auto

btn1_btn.onRelease = function(){
this.mcName.play();
}

```

then what you need to do is set you animation at frame 100 to tell the other mc to go to lable1

if you are using as3 itll look something liek this

```auto

//this sets up an eventListener for you button and then will execute the function playAnimation when the condition is met, in this case a mouse click event.

btn1_btn.addeventListener(MouseEvent.CLICK, playAnimation);
function playAnimation(event:MouseEvent):void
{
this.mcName.play();
}

```

Just rember to tell flash where you want to go at the end of you animation. Make a new keyframe on frame 100 and just put mcPath.gotoAndPlay(lable1);

that sould do it, hope it helps

---

<div class="post-metadata">

**Author:** ![helious](https://avatars.discourse-cdn.com/v4/letter/h/b9e5f3/32.png) [@helious](https://forum.kirupa.com/u/helious)\
**Post date:** [July 3, 2008, 3:45pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/3 "2008-07-03T15:45:10Z")

</div>

[quote=koolkrasher;2353110]if you are using as2 you would do something like so.

this will set the button up to play the animation when it is released.

```auto

btn1_btn.onRelease = function(){
this.mcName.play();
}

```

then what you need to do is set you animation at frame 100 to tell the other mc to go to lable1

if you are using as3 itll look something liek this

```auto

//this sets up an eventListener for you button and then will execute the function playAnimation when the condition is met, in this case a mouse click event.

btn1_btn.addeventListener(MouseEvent.CLICK, playAnimation);
function playAnimation(event:MouseEvent):void
{
this.mcName.play();
}

```

Just rember to tell flash where you want to go at the end of you animation. Make a new keyframe on frame 100 and just put mcPath.gotoAndPlay(lable1);

that sould do it, hope it helps[/quote]

Thanks for the Quick answer, but i dont understand it all.

I dont want the Button to animate after its been pushed.  
I want the content of the page to change.

Example:

Button 1 is pressed.  
the text and images on the page animates and fades away, and some new content appears.

The way i wanted to do this was to have an “Content Outtro” animation at frame 50 to 100, and then an actionscript on frame 100 (gotoandplay “Label1”). But without making 5 copies of the frames 50 to 100, with gotoandplay “Label1”, gotoandplay “Label2” etc. scripts on the end of each animation

P.S im using AS2.0

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 3, 2008, 3:49pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/4 "2008-07-03T15:49:49Z")

</div>

are you using as3 or 2?

---

<div class="post-metadata">

**Author:** ![helious](https://avatars.discourse-cdn.com/v4/letter/h/b9e5f3/32.png) [@helious](https://forum.kirupa.com/u/helious)\
**Post date:** [July 3, 2008, 4:07pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/5 "2008-07-03T16:07:59Z")

</div>

> [@koolkrasher;2353143](#):
>
> are you using as3 or 2?

AS 2 🙂

Im looking for some kind of code like this:

If button1 is pressed  
goto and play frames 50-100  
then goto and play Label 1

If button2 is pressed  
goto and play frames 50-100  
then goto and play Label 2

etc.

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 3, 2008, 5:24pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/6 "2008-07-03T17:24:06Z")

</div>

do u have a moc file u are using? itll be better to explain if i can see what you have done already

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 3, 2008, 6:08pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/7 "2008-07-03T18:08:19Z")

</div>

[quote=helious;2353157]AS 2 🙂

Im looking for some kind of code like this:

If button1 is pressed  
goto and play frames 50-100  
then goto and play Label 1

If button2 is pressed  
goto and play frames 50-100  
then goto and play Label 2

etc.[/quote]

I’d imagine a solution to this could be like this:

Button 1:

```php
gotoAndPlay(50);
btn_pressed = 1;

```

Button 2:

```php
gotoAndPlay(50);
btn_pressed = 2;

```

Button 3:

```php
gotoAndPlay(50):
btn_pressed = 3;

```

etc with the number of buttons you want.

Frame 100:

```php
if(btn_pressed == 1){
gotoAndPlay(label1);
}else if(btn_pressed == 2){
gotoAndPlay(label2);
}

```

Hope you get the idea, of course, this is a rather bad solution, just imagine if you have 100 buttons, but it should do the trick.

---

<div class="post-metadata">

**Author:** ![helious](https://avatars.discourse-cdn.com/v4/letter/h/b9e5f3/32.png) [@helious](https://forum.kirupa.com/u/helious)\
**Post date:** [July 3, 2008, 6:21pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/8 "2008-07-03T18:21:19Z")

</div>

[quote=gigaboost;2353223]I’d imagine a solution to this could be like this:

Button 1:

```php
gotoAndPlay(50);
btn_pressed = 1;

```

Button 2:

```php
gotoAndPlay(50);
btn_pressed = 2;

```

Button 3:

```php
gotoAndPlay(50):
btn_pressed = 3;

```

etc with the number of buttons you want.

Frame 100:

```php
if(btn_pressed == 1){
gotoAndPlay(label1);
}else if(btn_pressed == 2){
gotoAndPlay(label2);
}

```

Hope you get the idea, of course, this is a rather bad solution, just imagine if you have 100 buttons, but it should do the trick.[/quote]  
Great! EXCATLY what i was looking for.

Ill report back when i tried it out!

Should i not have a “OnRelease” on the buttons before the gotoandplay?

---

<div class="post-metadata">

**Author:** ![koolkrasher](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@koolkrasher](https://forum.kirupa.com/u/koolkrasher)\
**Post date:** [July 3, 2008, 7:16pm UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/9 "2008-07-03T19:16:43Z")

</div>

depends if u are scripting on the button or on the timeline.

if you on the button itll look like so

```auto

onRelease(){
gotoAndPlay(50):
btn_pressed = 3;  
}

```

if your on the timeline then its

```auto

this.buttonInstanceName.onRelease = function()
{
gotoAndPlay(50):
btn_pressed = 3;  
}

```

---

<div class="post-metadata">

**Author:** ![gigaboost](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gigaboost](https://forum.kirupa.com/u/gigaboost)\
**Post date:** [July 5, 2008, 1:50am UTC](https://forum.kirupa.com/t/how-do-i-call-an-animation-before-gotoandplay/265060/10 "2008-07-05T01:50:09Z")

</div>

[quote=helious;2353228]Great! EXCATLY what i was looking for.

Ill report back when i tried it out!

Should i not have a “OnRelease” on the buttons before the gotoandplay?[/quote]

Yeah, what koolkrasher said, just didn’t add it because it felt redundant. You SHOULD be able to add a variable to somethings name somehow, I just don’t know how, but it would make it easier if you have loads of buttons.
