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

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.

The earlier videos explained what a variable is, but the discussions were brief and limited to initial declarations. Now, we will see how to use variables in the context of Flash. Basically, a variable doesn't belong to any specific data type. We can assign any type of data to a variable but we must ensure that the variable is declared initially using the same data type.

The most important feature of variables which makes them so popular is their re-usability. Variables are just like containers in which anything can be saved. For example, imagine that we need to perform multiplication on 3 sets of numbers containing 3 integers each: [(1,2,3)(2,3,4)(7,8,9)]. Now to multiply these we need to write the trace line for each set.

Instead, if we use the variables (a,b,c ) and assign the first set of values to these variables then we can perform the multiplication of the first set using abc. Now, for the multiplication of the second set, nothing much changes but we assign the values of the second set to a,b and c. This way we can reuse the variables any number of times and reduce the length of the code.

Instead, if the values that are being operated are continuous numbers, then we can use the property of incrementing and looping with the help of variables which reduces the bulk of the code to a single loop. When there are many values to be calculated, using variables is the best option.

The use of variables is not just limited to numbers; strings can be assigned to them as well. We assign a string to a variable at the beginning and can perform any needed modifications on it. Later, if we want another string to be used instead of the present string, there is no need to rewrite the whole program. We just change the string that is assigned to the variable. Moreover, addition of strings seems difficult when we output the sum directly. Using variables for the addition of strings is the best option.

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