Flash ActionScript and Data Types

Flash ActionScript and Data Types
Some programming languages are more strict than others when it comes to following syntax and coding rules. For example, the HTML scripting language is somewhat forgiving when it comes to programming errors. You can have errors in your source code and your web page will still be viewable in the web browser. However, if you have worked with FlashR and ActionScript at all, you know that it is far less forgiving. Therefore, we need to be far more careful when writing our ActionScript code.

One of the coding rules that you will encounter many times when writing your ActionScript code is the use of data types. One place where you will need to use data types is when declaring a new variable. In a previous tutorial, you learned the code to create a new variable.

var name_of_variable = value;
var container = 20;

In the above code from the previous tutorial, we have not declared a data type for our new variable. We need to do that. Let's add the data type to the above code now.

var container:Number = 20;

As you can see, we first add a colon to the end of the name we have given to the variable. We decided to name the variable "container". So the colon is placed at the end and the data type is added to the right of the colon. In the example, the value of the variable is 20 and 20 is a number. Therefore, we need to declare the Number data type.

There are two other data types, which are the String and Boolean.

If we had set the initial value of our container variable to the word "David", then the data type would have been set to String because "David" is a text string of letters. We would also have needed to place quotation marks around the text string. String data is the only type of data that requires you to enclose the data between quotation marks.

The third data type is Boolean. You would use the Boolean data type whenever the value of the variable is true or false. One good example of this is a conditional statement. We could write a conditional statement that tests if a value is greater than 10. If the value is 11, the Boolean will be true. Otherwise, it will be false.

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.





RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map








Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.