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

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

Explorer ,
Jun 12, 2021 Jun 12, 2021

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.

TOPICS
ActionScript , Code , Error
946
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 ,
Jun 12, 2021 Jun 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

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
Explorer ,
Jun 12, 2021 Jun 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


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 ,
Jun 12, 2021 Jun 12, 2021

Sure! Please allow me to access the file.

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
Explorer ,
Jun 12, 2021 Jun 12, 2021

I have updated the file to be shared to anyone with the link. The code I am looking at is at fram 1559. Thank you so much for your help man.

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 ,
Jun 12, 2021 Jun 12, 2021

Thanks.

 

Do you have a simplified version of this file?

 

It seems my humble notebook cannot open your FLA. Haha

 

The opening process has not gone beyond 10% so far.

 

I just need the code and the button in frame you mentioned.

 

Regards,

JC

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
Explorer ,
Jun 12, 2021 Jun 12, 2021

Hey man, I just removed all the unnecessary assets and deleted layers that arent needed, It seems to have dropped by 100mb, and it should be easier to open now I hope.

Here is the new file.

 

 https://drive.google.com/file/d/1sN3vGcYEQev2PY8rSh8BtOc2ZpRTiWyw/view?usp=sharing

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
Explorer ,
Jun 12, 2021 Jun 12, 2021

I've created some screenshots, maybe this will be useful instead of looking at my animate file.

 

screenie for adobe1.png

screenie for adobe2.pngThe other 3 buttons are on another layer and I havent coded them, I am only focusing on that 1 button which i put on a separate layer called the rock_button_layer.

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 ,
Jun 12, 2021 Jun 12, 2021

Thanks.

 

Sorry, but I still cannot open your file.

 

Are you getting any errors?

 

Is your button an action Button symbol or a MovieClip instance acting as a button?

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
Explorer ,
Jun 12, 2021 Jun 12, 2021

Yes its a action button symbol. I haven't got a clue why things are messing up on it, as even the "Over" keyframe inside the button doesnt show up when I test it and hover over the button, it only flashes and then goes back to the "Up" keyframe state.

I'm going to try installing a newer version of adobe animate, and see if the problem still persists. Thank you so much for your help though man, I really appreciate it. I will update you if I manage to get things working.

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
Explorer ,
Jun 12, 2021 Jun 12, 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.

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
Explorer ,
Jun 12, 2021 Jun 12, 2021
LATEST

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.

 

code for adobe screenie1.pngcode for adobe screenie.png

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