Skip to main content
Inspiring
June 12, 2021
Question

How do I make my "Go to frame and play " button work with advanced layers on?

  • June 12, 2021
  • 1 reply
  • 1122 views

Hello there, I hope anyone can help me with this as I can't seem to find a solution anywhere at all on the internet for such a simple problem. I have a button on its own layer called rock_button_layer, and the code snippet on the button "go to a frame and play". Here is the code.

Rock_button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_8);

function fl_ClickToGoToAndPlayFromFrame_8(event:MouseEvent):void
{
gotoAndPlay(1560);
}

I need to keep advanced layers on as its important for my animation. All I want is for my button to work and I just can't seem to rack my brain over how to change the code with advanced layers on.

I hope someone can explain this to me please, thank you.

This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
June 12, 2021

Hi.

 

What version of Animate are you using?

 

In the most recent versions, you should be able to reference any instance directly, with or without using the advanced layers mode.

 

In older versions, you're gonna need to referece the layer that contains the instance first. For example:

import flash.display.MovieClip;
import flash.display.SimpleButton;

var layer:MovieClip = getChildByName("Layer_1") as MovieClip;
var button:SimpleButton = layer.getChildByName("Rock_button1") as SimpleButton;

button.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
	gotoAndPlay(1560);
}

 

Please let us know if this helps.

 

Regards,

JC

Inspiring
June 12, 2021

Thank you so much for you reply!

I am using Adobe Animate version 20.0.3

I just used your code but replaced layer_1 with rock_button_layer as thats what the layer is called with the button. However, It doesnt seem to play when I click then button. Do you know why this is the case? I even changed to go to frame 1561 but the button still doesnt play.

If looking at my adobe animate file would help, here it is  but it is 294mb: https://drive.google.com/file/d/1irAke5ZBrdaJBbk0NpBB2FugqQMLCicO/view?usp=sharing


Inspiring
June 13, 2021

Hey man, so I tested on 21.0.6 but the same thing was happening, but I figured a way to fix it! So what was happening was I had 3 other buttons that were on the same layer while the 4th button was on a separate layer. I deleted the layer with the 3 buttons and just left the rock_button1 on its own layer, with your code that you provided on the button and it worked!

 

However, I need these 4 buttons to be present and each to go to a specific frame and play. I then tried to put each button with the same code on the same frame, like this:

import flash.display.MovieClip;
import flash.display.SimpleButton;

var layer:MovieClip = getChildByName("rock_button_layer") as MovieClip;
var button:SimpleButton = layer.getChildByName("Rock_button1") as SimpleButton;

button.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
gotoAndPlay(1877);
}

import flash.display.MovieClip;
import flash.display.SimpleButton;

var layer:MovieClip = getChildByName("devil_button_layer") as MovieClip;
var button:SimpleButton = layer.getChildByName("devil_button") as SimpleButton;

button.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
gotoAndPlay(2000);
}

import flash.display.MovieClip;
import flash.display.SimpleButton;

var layer:MovieClip = getChildByName("angel_button_layer") as MovieClip;
var button:SimpleButton = layer.getChildByName("angel_button") as SimpleButton;

button.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
gotoAndPlay(2050);
}

import flash.display.MovieClip;
import flash.display.SimpleButton;

var layer:MovieClip = getChildByName("glut_button_layer") as MovieClip;
var button:SimpleButton = layer.getChildByName("glut_button") as SimpleButton;

button.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
gotoAndPlay(2100);
}

 

but I get this error:

Scene 1, Layer 'Actions', Frame 1559 1084: Syntax error: expecting rightbrace before end of program.

I double-click it and it takes me to the beginning of the code on the frame.

I hope you can help me figure this out please, thank you.


Sorry, no I didnt get that error, that was an error from when i didn't close the code off with a bracket. However when i did close the code off with a bracket, I got these errors. I hope you can help me figure out why I got these errors.