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

How to progress a scene or continue the current scene with a button?

Explorer ,
Nov 27, 2018 Nov 27, 2018

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.

631
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

correct answers 1 Correct answer

Community Expert , Nov 29, 2018 Nov 29, 2018

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:

animate_cc_as3_navigate_frames_labels_and_scenes.png

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>();

  

...
Translate
Community Expert ,
Nov 27, 2018 Nov 27, 2018

Hi.

Can you provide more details?

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 ,
Nov 28, 2018 Nov 28, 2018

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.​

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 ,
Nov 29, 2018 Nov 29, 2018
LATEST

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:

animate_cc_as3_navigate_frames_labels_and_scenes.png

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

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