ActionScript for controlling animation (interactivity)

New Here ,
Oct 31, 2020 Oct 31, 2020

Copy link to clipboard

Copied

Dear comunity,

 

I'm trying to find a way how to make animation kind of interactive (not buttons). I am in need of stop at some frame and wait for keypress. There is a script which was posted here few time, which help to stop on each frame and continue on ANY key pressed. 

I'd like to have something similar, but with possibility to stop only on some frames. Idelly would like to have 3 scripts:

1. General (working over wole timeline 😞 when I press predefined key (ideally "-"), the animation will go back to starting frame (like reset)

2. Wait for any key and continue (when I put this script on frame 10, animation will stop there and wait until I press any key and continue to next rame)

3. Wait for ENTER key and continue (similar to script 2 but only ENTER key will move us to next frame)

 

It would be nice to have all this functions in one script, and use some kind of marks on the timeline (I used this in Macromedia Director many years ago ), but I'm not sure if this is doable with Animate. If this is not possible with animate, I'll have to probably combine 1+2 and 1+3 and put them on the timeline where I need to wait for ANY or ENTER key.

 

What do you think? Is this somehow possible?

 

Thank you for your time and stay safe everyone there!

TOPICS
ActionScript, How to, Timeline

Views

62

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

are the frames where you want to pause (while awaiting keypresses) the same in any one project?  (eg, in project1, you'll always pause on frames, 3,44,66 while awaiting a keypress?)

 

if yes, add stop() to the frames where you want to pause (eg, frame 3,44,66) and in frame 1, use:

 

import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);

function keydownF(e:KeyboardEvent):void{
// -, 45 enter, 13
if(e.charCode==45){
gotoAndStop(1);
} else if(e.charCode==13){
play();
}
}

 

if no, in a given project, what determines the frames where you want to pause?

 

 

Likes

Translate

Translate

Report

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
New Here ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

nope, they're different in each project.

Here is example:

I'd like my presentation to wait for ENTER key on frames: 10, 15 and 20

I'd like my presentation to wait for ANY key on frames 25-60

I'd like my presentation to go back to Frame 1 whenever I press "-" 

 

I'm not sure what is the best way in Animate to determine on which frame I want to stop and wait for action (I'm really new to Animate), I can imagine to put keyframe on each of tese and name it somehow or paste some script, etc... Whatever will be best vissible on the timeline. When I'm thinking of it, I can for ex. create two extra timelines, one will be named "ENTER" and the other one "ANY". And if I add keyframe to one of these timelines, it will wait for ENTER or ANY key depends on in which timeline this keyframe is?

 

Is something like this even possible?

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

LATEST

your example can be encoded:

 

import flash.events.KeyboardEvent;
import flash.events.Event;

 

var enterA:Array = [10,15,20];  // await enter key on these frames
var anyA:Array = [25,60];  // await any key on frames 25,26,...,60

 

this.addEventListener(Event.ENTER_FRAME,enterframeF);

function enterframeF(e:Event):void{
for(var i=0;i<enterA.length;i++){
if(this.currentFrame==enterA[i]){
this.stop();
}
}
if(this.currentFrame>=anyA[0] && this.currentFrame<=anyA[1]){
this.stop();
}
}

stage.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);

function keydownF(e:KeyboardEvent):void{
if(e.charCode==45){
this.gotoAndStop(1);  // you might want this.gotoAndPlay(1)
} else if(e.charCode==13 && enterA.indexOf(this.currentFrame)>-1){
this.play();
} else if(this.currentFrame>=anyA[0] && this.currentFrame<=anyA[1]){
this.play();
}
}

 

 

Likes

Translate

Translate

Report

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