IntroductionBased upon ECMA Script, Actionscript is the scripting language of Macromedia Flash. A scripting language is a way to communicate with a program; you can use it to instruct the Flash what to do and to ask it to interact with other programs. Hence it opens Vista to create interactive movies.Actionscript finds a wide amount of uses in the industry of website and software development. Besides, Actionscript is also quite handy in database applications and elementary robotics.Programming Fundamentals
- Ø Variables and constants
In ActionScript, a variable is composed of three different parts:
- variable name
- type of data that the variable can store
- actual value stored in the computer’s memory
E.g. var value1:Number = 19;In this case, we’ve created a variable named value1, which will hold only Number data=19On the similar lines we have a constant .The difference between a constant and a variable is that a constant can only be assigned a value only once in a program. The syntax for declaring a constant is almost the same as that of a variable, the only change being the use of keyword const in spite of var.E.g. const Pie:Number = 3.14;Ø Data TypesActionScript is rich in data types. For Example: number, int, uint, BooleanA few complex types are: Movieclip, TextField, SimpleButton and Date.How to make an application in ActionScriptThe creation of an application through ActionScript can be best gasped by an illustration. Although you may find it hard to comprehend it at once, a repeated insight will help you to understand the process quite easily.
- Ø Here we are going to illustrate an animation portfolio piece in which we will add interactive behavior to animation. This will be done by adding two buttons which the user can click: one of them is to start the animation, and the other to navigate to a separate URL. The process of creating this piece can be divided into these main sections:
- Prepare an FLA file
- Creation and addition of the buttons.
- Write the code.
Prepare an FLA File: Open the FLA file and chose where you want the buttons on the screen. Now place a new layer for addition of buttons, above the other layers in the Timeline; name it as buttons. Now add a new layer on similar lines but this time add actionscript code, above the buttons layer, and name it actions.Creation and addition of the buttons: Create and add two buttons and name them as playButton and homeButton.Write the ActionScript code:Code to cease the play head when it enters Frame 1:
- Select the key frame on Frame 1 of the actions layer.
- To open the Actions panel, from the main menu, choose Window > Actions.
- Enter the following code in the script pane:
Stop ();Code to start the animation when the play button is clicked:Enter the following code at the bottom of the script:function startMovie(event:MouseEvent):void{ this.play(); }Now add playButton.addEventListener(MouseEvent.CLICK, startMovie);Code to send the browser to a URL when the home page button is clicked:Enter the following code at the bottom of the script:function gotoDesiredPage(event:MouseEvent):void{ var targetURL:URLRequest = new URLRequest("http://example.com/"); navigateToURL(targetURL);}The above code defines a function called gotoDesiredPage(). This function first creates a URLRequest instance representing the URL http://example.com/, and then passes that URL to the navigateToURL() function, causing the user’s browser to open that URL.Now enter this line of code:homeButton.addEventListener(MouseEvent.CLICK, gotoDesiredPage);Thus with the use of functions you can split your program into various sub problems and programming becomes easy.It is the same with any other programming language. It also reduces the redundancy in the code.The bottom-line is- ActionScript runs on similar lines as that of other Object Oriented Programming Languages with similar class structures, flow control, packages and so on.