• home
  • forum
  • my
  • kt
  • download
  • ActionScript Data types

    Author: 2007-06-06 15:00:54 From:


    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 SequenceCharacter
    \bBackspace
    \\Backslash
    \"Double Quotation mark
    \'Single Quotation mark
    \fForm feed
    \nLine feed
    \rCarriage Return
    \tTab
    \000-\377Character in Octal
    \x00-\xFFCharacter 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)

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (66)
      Utilities (19)
      Getting Started (71)
      Video (10)
      Interactivity (21)
      Web Design (22)

    New

    Hot