Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here










 

Google

Search WWW   
FlashAdvisor.com

 Home > Tutorials  > Beginners

DataType in Flash

Author: T Norman | Email
Website : www.ntdesigns.net


Advertisement

What's a Data Type?
Simply put, a data type defines the type of data a variable or actionscript element can hold. In Flash 5 there are two types of data types - primitive and reference.
Let's begin with the primitive data types. If you have used flash 4 previously, the primitive data types will be familiar - strings, numbers and boolean. The term "primitive" is used because they were the "first" or "original" data types in programming.

Strings
A string is simply a 'string' of characters like "Hello how are you?". Each character can be a number, letter or symbol have their own numerical code called an ASCII code. For example, the ASCII code for the letter "a" is 97. More on this later.
A string is defined by quote marks and tells the computer that everything between the quote marks should be taken literally, including the spaces. All this means is if you use the string "Hello add variable" you are not implying a function or expression (although it looks like one), you are simply (literally) intend it to be the string of characters "Hello add variable". Here's another example, "Hi there, this is 1 string of letters, numbers and symbols - &%$#^!!!
but it is still a string because its enclosed by brackets!!!"
Now you're probably asking "How do I use quote marks in my string with out affecting the string itself?". Flash 5 has taken this into consideration and created what are called "escape" characters. Every escape character is preceded with a back slash (). So to add a quote mark, a single quote mark or a back slash character to your string, insert, ", ' or \ respectively. To help you better understand this have look at the example:
output = "The code is "big bird".";
This example will output the string, The code is "big bird". As you can see the quote marks in the string would have effected the string if escape characters hadn't been used. Here is the complete table of escape characters.

Numbers and Boolean
Numbers are another form of literal although this time you don't use quote marks. There is a very distinct difference between the number 1 and the character "1". The first is a number, the second is a string. The way you were taught numbers in school is how you should treat the number data type. Add them, subtract them and multiply them 'til your heart's content!
This is what a number looks like - 120437289 (just in case you had forgotten :)
The Boolean data type is a source of confusion for some novice programmers but it is a very simple concept. It is one of the fundamental concepts of computing, on and off. Other manifestations of this are "yes/no" and the binary numbers "1/0", the most common however is True and False. False holds the value of 0 and True holds any non-zero value, but usually it's 1.
True (1), False (0)
That's it for primitive data types but remember all three physically hold their values like a container. The information presented here has simply been an introduction. If you are seeking more information, we will be pursuing these data types further in the tutorial on Operators. But before we jump ahead of ourselves let's introduce you to the more complex data types.

Reference Data Types
The reference data type is more advanced. The difference between them and primative data types is very simple - as I mentioned before the primitive data types physically hold the value (the container analogy), the reference data type instead holds information that "points" to where the actual value resides (where the container is). Objects and movie clips are the two types of reference data types.
The benefit of using a reference is you only have to change a value once. All references to that particular value will then be reflected throught your movie. An example of an Object data type is an Array is essentially an indexed group of variables.
Let's have a look at an example of some actionscript to highlight the way reference data types work. In the example we'll be using an Array Object. But for now, don't worry about the details of an array just think of it as a table with rows of cells (a cell in an array is called an element), in this case we're using a single row of elements. Arrays will be discussed in more detail later.

A Objects
Objects can sometimes be a hard concept to grasp. I like to think of objects as small self contained piece of code that has its own "identity" and "methods" (In Flash 4 these would have been called "actions"). Think of a physical object like a person who has an identity (a name) and methods such as walk, run, hold, and my favourite, sleep.
The following is a list of all the predefined objects available in Flash 5.



In Flash, you can use predefined objects or you can custom build your own, like "customer", or "circle". We'll be teaching you how to build your own objects in a later tutorials.
fter we made a copy of "myArray" and called it "copyOfArray", we changed the value of copyOfArray[3] by changing the corresponding element in "myArray". We didn't have to touch "copyOfArray". This is essentally a reference in action. The array "copyOfArray" only holds information that points to a physical place in your computers memory where the value is stored (consider it an address). Confused?

Let's expand on the address analogy. If I gave you my website address, I wouldn't be giving you all my website files. I would simply be giving you some information that points to a physical location on a server where my website files reside. This is very different to the way primitive data types work, which physically contain the values. To carry on the analogy, a primative would be like me handing over a disk with all my website files instead of giving you an address.
A movie clip data type is still classed as an object but its unique qualities deserve a mention. Some of the differences is that the movie clip has a timeline and can play animation. It's the only data type that refers to a graphcial element. The methods assigned to the movie clip object allow you to control the clip.

Movie Clip Methods
Finally here is a complete list of the object movie clip's methods. Looking through the list you notice some old favourites from Flash 4 like load movie, getURL and stop. You will also notice how many of the functions in the old actions are now a separate methods themselves, like load variables and removeMovieClip.
To learn more about these actions consult your flash help file or the Flash 5 actionscripting tutorial section. And just remember, the concept of a method is very similar to an action in Flash 4 except that a method now belongs to an object.



If you're finding this hard to stomach don't stress! The only way to learn to program is the get in there and do it. The more you experiement the more you will develop an understanding of how the pieces of the puzzle come together. Also you're not the only person doing this, Flash 5 is a new product and thousand of designers are going through what you are. If you have questions or problems come to the flashkit.com forums and seek help. There are tens of thousands of members and moderators
who would love to help out.
That brings us to the end of the introduction to actionscripting data types. In this tutorial we have covered the primitive data types - strings, numbers and boolean - and discussed the reference data types and its predefined objects including the movie clip.

| 1 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

41 users online