http://www.bhmadhukar.cjb.net


[ MORE TUTORIALS] [ GOD AND GODDESS SLOKA'S & POOJA'S ] [ FLASH MOVIES ] [ HOME ] [ CONTACT ME ]


Flash 5.5 Tutorials


Flash 5.5 tutorial - [ Beginners ]

Know about datatypes in Flash.

Datatypes:

A data type describes the kind of information that a variable or Action Script element can hold. Basically, there are two kinds of data types. They are a) primitive and b) reference. The primitive data types are string, number and Boolean. They have a constant value and therefore, they can hold the actual value of the element they represent. On the other hand, the reference data types i.e., movie clip and object have values that can change and therefore, contain references to the actual value of the element. Variables containing primitive data types behave differently in certain situations than those containing reference types.

Let us know about some of the datatypes;

a) String Datatype

A string is a sequence of characters such as letters, numbers, and punctuation marks. You can enter strings in an ActionScript statement by enclosing them in single or double quotation marks. Strings are treated as characters instead of as variables.

"Hello! How Are You?" // user-friendly string
"smile" // Double quotes are also acceptable too

For example, in the following statement, "BHMK" is a string:

AuthorName= "BHMK";

You can use the addition (+) operator to concatenate or join two strings. ActionScript treats spaces at the beginning or end of a string as a literal part of the string.

SayGreeting = "Hello! Welcome, " + AuthorName;

To include a quotation mark in a string, precede it with a backslash character (\). This is called escape sequences. The following table shows all the Action Script escape characters:

Escape sequence Character Specification Including ASCII
\b

Backspace character (ASCII 8)
\t Tab character (ASCII 9)
\n

Line-feed character (ASCII 10)
\r

Carriage-Return character (ASCII 13)
\f Form-feed character (ASCII 12)
\"

Double quotation mark
\'

Single quotation mark
\\

Backslash
\u0000 - \uFFFF A 16-bit Unicode character specified in hexadecimal
\000 - \377

A byte specified in octal
\x00 - \xFF

A byte specified in hexadecimal

b) Number Datatype

The number data type is a double-precision floating-point number. You can manipulate numbers using the arithmetic operators addition (+), subtraction (-), multiplication (*), division (/), modulo (%), (Pre/Post) increment (++), and
(Pre/Post) decrement (--).

Most of the programming languages distinguish between two kinds of numbers. They are integers and floating-point numbers. An integer is a whole number that has no fractional part. Integers are either positive or negative and include the number 0. Floating-point numbers can include a fractional value represented after a decimal point, as in 1.46, 150.05, and.
Example 2, 12403, -5, and -10000 are integers, but 1053.67, -3.1415, and 1/2 are floats.

c) Boolean Datatype

A Boolean value is one, that is either True or False. Action Script also converts the values true and false to 1 and 0 when it is appropriate. Boolean values are most often used with logical operators in ActionScript statements that make comparisons to control the flow of a script.

d) Undefined Datatype

Most of the datatypes we've explored so far have been used for storing and manipulating information. But, undefined datatype has a purpose. It is used to check whether a variable exists or whether a variable has yet been assigned a value. The undefined datatype has only one validl value, the primitive value undefined.

When we first define a variable, it is assigned the value undefined by default:

var AuthorName;

To the interpreter, the preceding statement reads:

var AuthorName = undefined;

To check whether a variable has a value, we can compare the variable to undefined, as in:

if (AuthorName != undefined)
{
     // AuthorName has a value, Write the code
}

Note that an undefined value is converted to the empty string when used as a string.

For example, if AuthorName is undefined, the trace( ) statement will display "" (an empty string):

var AuthorName;

trace(AuthorName); // It displays nothing (just an empty string)

e) Object Datatype

An object is a collection of properties. In general, each property has a name and a value. The value of a property can be any Flash data type, even the object data type. This allows you to arrange objects inside each other, or "nest" them. To specify objects and their properties, you use the dot (.) operator.

For example, in the following code, ShirtColor is a property of Person, which is a property of Human:

Human.Person.ShirtColor

f) Movie clip Datatype

Movie clips are symbols that can play animation in a Flash movie. They are the only data type that refers to a graphical element. The movie clip data type allows you to control movie clip symbols using the methods of the MovieClip object.

g) Null Datatype

The "Null" type is nearly identical to the undefined type. Like the undefined datatype, the null datatype is used to represent a lack of data and has only one valid value, the primitive value null.

We assign null to a variable, array element, or object property to indicate that the specified data container does not contain a valid number, string, boolean, array or object value.

Note that null only compares equal to itself and undefined:

null == undefined; // true
null == null; // true

That's all my dear friends. Hope You Enjoyed It!!! Don't forget send mail to me.

"Fundamentals are the Route to the Destination" - BHMK

Go Home


Hosted by www.Geocities.ws

1