02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Numbers, int And unit

Are you ready to learn two new variable types and compare them to the Number data type? There are three types of numbers in ActionScript 3.0 : Number, int and uint. What are they and when should we use them?

We have seen how to deal with variables and operators in this course. Now let's take a look at data types associated with these variables to wrap up the coding basics. There are a number of data types that can be worked with according to our need. But as of now, it's enough to understand about a few numeric data type such as Number, int and uint.

Numbers

Number is a common word we used till now. The use of this data type was explained before when we started working with variables. As we all know, Number is a data type used to declare a variable of type Number (such a 1.13 or 999.) We know the difference between a string and a number, and the fact that data type mismatches can cause errors. Now we will learn what happens if the number used is a floating point number. A floating point number has a decimal value, for example 3.33 or 999.99999. Number refers to a floating point value by default. No need to worry if the output is a floating point value because if the variable was declared as Number, the application reserves memory for the decimal values as well.

Int and uint

We know that a lot of memory is used for a Number because of that decimal point; if we know that the value used will always be an integer, then the memory reserved for the decimal points is of no use. In that case, we can use the keyword int to declare an integer variable: var b:int; This will reserve memory for a single integer and displays the same. it's also useful when the output is a floating point value (say 3.33333) and we don't want the decimal points to be shown on the output panel. For this to happen, we must declare the variable as data type int. This will not only save memory but will also round off the output to an integer (in this case 3.3333 rounded off to 3.) But this works only when you already know that the numbers you're dealing with are integers.

There are also a few possibilities where we not only need an integer but a positive integer. These situations are rare; so for the most part you should always use int unless you need to access really large numbers. As int stores both positive and negative numbers, the amount of numbers int can show is exactly 50% of what the unit can. Don't use uint unless you need to access really big numbers. Why do we say that? Mainly because if you put inside a uint the value '-5' you'll find a totally different number in it as it's out of bounds: the actual number that will be in it will be the maximum number -5 (and that is a very very big number.)

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!

Intro

In our mission to learn how to become a developer, things are getting more complicated. We will learn about the importance of variables, brackets, operators and even talk more deeply about data types

01:52

What Opens Must Close

Quick detour - I want to let you in on a little secret. It's my favorite shortcut in the book and will help you manage the many brackets with which you work.

06:33

Addition

Let's study string addition! We will see how we add strings together and how we add numbers together. And if you think that isn't enough, we'll even look at error 1084 and figure out how to avoid it.

03:33

Mixing Strings and Numbers

When working with numbers and strings it's important to prevent Compiler (Flash) from automatically converting data so you'll not be automatically confused.

02:04

Converting Strings to Numbers

How do we take that string and let Flash know we actually want it to be a number? The answer is simple: learn a new function. This function type is called Casting.

01:16

Using Variables

So, we have variables and we know how to create them but how can we actually use them and for what? We agree, it's time to see them in action through this video.

06:15

What are Primitives?

It’s important to differentiate between primitive and complex data types in Flash. Have no clue what primitive values are, well jump in and let's figure it out!

02:09

Deeper Look: Defining Variables

Now that we know what variables are it's time to look deeper into their structure and how to play with them. Also, we'll learn about a new error type we can now check to avoid - Error 1120.

04:10

Deeper Look: Math Operators

Things are starting to fall into the right place! Lets revisit the math operators and add a few new tricks and shortcuts. Also learn about a new operator (%) used to find the modulus of two numbers.

05:36

Numbers, int And unit

Though all three types Number, int and uint are used to represent numbers, there are few minor differences between them which help us save time. Lets learn what are they and when should we use them

07:19

Boolean

Boolean are simple. They are really only place holders that can hold only two possible values: true or false (0 or 1, yes or no...) Lets learn how Boolean variables are used in programming.

01:48