Contents

Adding Audio Capturing the Keyboard

Adding JavaScript

This tutorial assumes you have a basic understanding of this software.

This tutorial shows three ways JavaScript can be used to add more complexity to your movies. Create a new movie. Add a 'Button' and a 'Text Box'.


Adding JavaScript 1

Change the 'Script ID' of the 'Text Box' to 'Text1'.


Adding JavaScript 2

In the movie properties add the following script to the 'General' script. The 'General' script is for adding variable declarations and functions that can be used from anywhere within the movie.


Adding JavaScript 3


var Counter=0;

In the button properties add the following script to the 'On Click' script.



Counter++;
TextBoxSet("Text1","The button has been clicked "+Counter+" times.");

Click 'Play' to test the movie. Every time the button is pressed, the value of Counter is increased and a message is show in the text box.


Play Play

Adding JavaScript 6

The 'On Update' event

The movie includes and 'On Update' event which is called every time the movie is updated, which could be many times a second.

Start a new movie and add a 'Text Box'.


The 'On Update' event 7

The 'On Update' event 8

Change the 'Script ID' of the 'Text Box' to 'Text1'.


The 'On Update' event 9

Add the following script to the movie 'On Update' script event.



var CurrentDate=new Date();
TextBoxSet("Text1","The time is "+CurrentDate.toTimeString()+".\r\nThe date is "+CurrentDate.toDateString()+".");

Click play and the 'Text Box' will be constantly updated with the time and date.


Play Play

The 'On Update' event 11

The 'On End' event

Start a new movie and recreate the circle animation from the 'Getting Started' tutorial.


The 'On End' event 12

Turn off 'Loop' in the movie properties.


The 'On End' event 13

Add the following script to the movie 'General' script. This creates and new counter variable.



var LoopCounter=0;

Add the following script to the movie 'On End' script event.



LoopCounter++;
if(LoopCounter<3){
GotoAndPlay(0);
}

Click 'Play' to test the movie. The animation will play 3 times before stopping.


Play Play

Adding Audio Capturing the Keyboard