ActionScript tutorial  
  Home Computer Graphics Tutorials Tutorials Web Design tutorials Forums Computer Graphics Community Interview Interview Articles Articles Making Making About About US Contact us
 
*Home / Tutorials / Adobe Flash / ActionScript Data types
     
Maya tutorials   Autodesk Maya
Photoshop tutorials   Adobe Photoshop
Illustrator tutorials   Adobe Illustrator
flash tutorials   Adobe Flash
3Ds max tutorials   Autodesk 3D's Max
Premiere tutorials   Adobe Premiere
Dreamweaver tutorials   Adobe Dreamweaver
*
 

ActionScript Data types


Author: Animator   Level : Beginner   Environment : Adobe Flash MX Professional 2004
User Rating  : * * * * *  
 
 
This tutorial talks about the three most fundamental elements of ActionScript scripting language. Like any other scripting language ActionScript several type of data. A data type describes the kind of information a variable can hold. There are two types of data types built into ActionScript. Primitives and Reference.

Primitives have a constant value and therefore can hold the actual value of the element they represent. Reference types have values that can change.

String
A string data type is a sequence of characters. in ActionScript strings will be enclosed in single or double quotes. For example:
siteName = "www.cgshelf.com";
We can use '+' sign as the string concatenation operator.  For example

var user="CGShelf User";
var message = "Hello"+user;

assigns "Hello CGShelf User" to the variable message.

Escape Characters
There are some characters that cannot be entered directly such as ', ",  \ etc. To enter these characters in ActionScript we are using the escape characters. There is also a mechanism for directly entering the value of a character in octal or hexadecimal. To enter a character in Octal notation use the backslash followed by three digit octal number. For example to enter 'a' in Octal use '\141'. Similarly for entering the character in hexadecimal format user backslash followed by a 'x' and the hexadecimal number. For example to enter 'a' in hexadecimal use '\x0061'. The following table shows the available escape characters in ActionScript.

Escape Sequence Character
\b Backspace
\\ Backslash
\" Double Quotation mark
\' Single Quotation mark
\f Form feed
\n Line feed
\r Carriage Return
\t Tab
\000-\377 Character in Octal
\x00-\xFF Character in Hexadecimal
\u0000 - \uFFFF A 16-bit Unicode character specified in hexadecimal


Number
Number data type is used for storing real numbers. The number data type is a double-precision floating-point number. For example
var price=100.10;

Boolean
Boolean type is used for representing logical values. A Boolean value can have only two values true or false. This is the type returned by all the relational operators like <, > etc. ActionScript converts the values true and false to 1 and 0 when appropriate.  For example.

var flag = true;

Object
An object is an instance of a  class. It is a collection of properties and methods. Each property has a name and a value. To access a property of an object we use the dot (.) operator. For example, to access the name property of object site we use
site.name
We will look into the details of creating custom objects later.

MovieClip
Movie clips are symbols that can play animation in a Flash application. This is the only data type that refers to a graphic element. The MovieClip data type is an object of class MovieClip. By using the methods of MovieClip class we can control the symbols of MovieClip. To access the methods of MovieClip class we use the dot operator like any other objects. For example
mc.startDrag(true);
Where mc is the object of MovieClip class and startDrag is a method of MovieClip class.

Null
Null data type represents lack of data. A variable can have a null value in a variety of situations.
  • To indicate that a variable has not yet received a value
  • To indicate that a variable no longer contains a value
  • As the return value of a function, to indicate that no value was available to be returned by the function
  • As a parameter to a function, to indicate that a parameter is being omitted
Undefined
The undefined data type has only one value, undefined. It means that a variable hasn't been assigned a value.

You can determine the data type of a variable using the typeof operator For eg:
typeof(flag)
 
 
 
  Bookmark   Googlize this * Add to Yahoo * Add To_Delicious * Digg It * Scrutinize this * Spurl this * Furl * Socializer * Onlywire
     
  Discuss This   Add to Any * Add this * Blink It *
 
*

Home | Tutorials | Forums | Interviews | Articles | Making | About the Team | Terms and Conditions | Privacy Policy | Contact us
Copyright © 2006-2007 CGShelf.com. All Rights Reserved