Copy link to clipboard
Copied
How would I progress a scene or go onto another scene by pressing a button? I'm trying to make something where there is a loop of audio/visuals until you press a button and then it continues.
Hi.
Here is a complete demo for you to better understand how frames, labels, and scenes can be used to navigate and show animations.
Preview:
AS3 code:
...import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.FocusEvent;
import flash.text.TextField;
var defaultFrameInputText:String = "Frame or Label...";
var defaultSceneInputText:String = "Scene...";
var input:*;
function getLabels(target:MovieClip = null):Vector.<String>
{
var vector:Vector.<String> = new Vector.<String>();
Copy link to clipboard
Copied
Hi.
Can you provide more details?
Regards,
JC
Copy link to clipboard
Copied
Hey. I'm afraid I don't know how to be more specific. I'm a bit of a novice at Animate. I'd like one scene of a background image, and there's a button on the screen. When you click that button someone walks into frame and plays out a set animation.
Almost like the beginning of this: LARRY: Doug-Out or this: Fleeing the Complex.​
Copy link to clipboard
Copied
Hi.
Here is a complete demo for you to better understand how frames, labels, and scenes can be used to navigate and show animations.
Preview:
AS3 code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.FocusEvent;
import flash.text.TextField;
var defaultFrameInputText:String = "Frame or Label...";
var defaultSceneInputText:String = "Scene...";
var input:*;
function getLabels(target:MovieClip = null):Vector.<String>
{
var vector:Vector.<String> = new Vector.<String>();
if (!target)
target = root as MovieClip;
for (var i:uint = 0, total:uint = target.currentLabels.length; i < total; i++)
vector.push(target.currentLabels.name);
return vector;
}
function getScenes(target:MovieClip = null):Vector.<String>
{
var vector:Vector.<String> = new Vector.<String>();
if (!target)
target = root as MovieClip;
for (var i:uint = 0, total:uint = target.scenes.length; i < total; i++)
vector.push(target.scenes.name);
return vector;
}
function gotoPreviousFrame(e:MouseEvent):void
{
prevFrame();
if (currentFrame == currentScene.numFrames)
setNavigation();
}
function gotoNextFrame(e:MouseEvent):void
{
nextFrame();
if (currentFrame == 1)
setNavigation();
}
function gotoPreviousLabel(e:MouseEvent):void
{
var labels:Vector.<String> = getLabels();
gotoAndStop(labels[Math.max(labels.indexOf(currentLabel) - 1, 0)]);
}
function gotoNextLabel(e:MouseEvent):void
{
var labels:Vector.<String> = getLabels();
gotoAndStop(labels[Math.min(labels.indexOf(currentLabel) + 1, labels.length - 1)]);
}
function gotoPreviousScene(e:MouseEvent):void
{
if (getScenes().indexOf(currentScene.name) > 0)
{
prevScene();
setNavigation();
}
}
function gotoNextScene(e:MouseEvent):void
{
if (getScenes().indexOf(currentScene.name) < scenes.length - 1)
{
nextScene();
setNavigation();
}
}
function gotoFrameOrLabel(e:MouseEvent):void
{
if (input && input != 0 && input != "")
{
if (isNaN(input))
{
if (getLabels().indexOf(input) > -1)
{
gotoAndStop(input);
setNavigation();
}
}
else
{
if (uint(input) > 0 && uint(input) <= currentScene.numFrames)
{
gotoAndStop(input);
setNavigation();
}
}
}
frameOrLabelText.text = defaultFrameInputText;
}
function gotoScene(e:MouseEvent):void
{
if (input && input != 0 && input != "" && getScenes().indexOf(input) > -1)
{
gotoAndStop(1, input);
setNavigation();
}
sceneText.text = defaultSceneInputText;
}
function focusInHandler(e:FocusEvent):void
{
if (e.target == frameOrLabelText)
frameOrLabelText.text = "";
else if (e.target == sceneText)
sceneText.text = "";
}
function focusOutHandler(e:FocusEvent):void
{
if (e.target is TextField)
input = (e.target as TextField).text;
if (e.target == frameOrLabelText)
frameOrLabelText.text = defaultFrameInputText;
else if (e.target == sceneText)
sceneText.text = defaultSceneInputText;
}
function setNavigation():void
{
if (!previousFrameButton.hasEventListener(MouseEvent.CLICK))
previousFrameButton.addEventListener(MouseEvent.CLICK, gotoPreviousFrame);
if (!nextFrameButton.hasEventListener(MouseEvent.CLICK))
nextFrameButton.addEventListener(MouseEvent.CLICK, gotoNextFrame);
if (!previousLabelButton.hasEventListener(MouseEvent.CLICK))
previousLabelButton.addEventListener(MouseEvent.CLICK, gotoPreviousLabel);
if (!nextLabelButton.hasEventListener(MouseEvent.CLICK))
nextLabelButton.addEventListener(MouseEvent.CLICK, gotoNextLabel);
if (!previousSceneButton.hasEventListener(MouseEvent.CLICK))
previousSceneButton.addEventListener(MouseEvent.CLICK, gotoPreviousScene);
if (!nextSceneButton.hasEventListener(MouseEvent.CLICK))
nextSceneButton.addEventListener(MouseEvent.CLICK, gotoNextScene);
if (!frameButton.hasEventListener(MouseEvent.CLICK))
frameButton.addEventListener(MouseEvent.CLICK, gotoFrameOrLabel);
if (!sceneButton.hasEventListener(MouseEvent.CLICK))
sceneButton.addEventListener(MouseEvent.CLICK, gotoScene);
if (!frameOrLabelText.hasEventListener(FocusEvent.FOCUS_IN))
frameOrLabelText.addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
if (!stage.hasEventListener(FocusEvent.FOCUS_IN))
stage.addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
if (!stage.hasEventListener(FocusEvent.FOCUS_OUT))
stage.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
}
function start():void
{
stop();
setNavigation();
}
start();
FLA download:
animate_cc_as3_navigate_frames_labels_and_scenes.zip - Google Drive
You don't need to understand the code above that handles the navigation of my sample.
Simple gotoAndStop and gotoAndPlay calls with button clicks will be enough.
My sample goal is to help you visualize what would be best for your needs.
If you want to learn the basics about timelines, navigation, and code, please don't forget to visit the official help (Adobe Animate Learn & Support​) or to search for a good tutorial on YouTube.
Regards,
JC
Find more inspiration, events, and resources on the new Adobe Community
Explore Now