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

Deeper Look: Defining Variables

<p>Now that we know what <a href="/courses/video/5/157/Using-Variables.html">variables</a> are, it's time to look deeper into their structure and how to play with them. Also, we will learn about a new <a href="/courses/video/4/155/Error-1067-Implicit-Coercion.html">error</a> type we can now check to avoid: Error 1120. </p> <p>Declaring and assigning variables is not new to us. We have discussed variables in almost every other video. However, we didn't dig very deeply before, stating it would be discussed later. Now it's the time to know everything about variables and look more deeply into them. </p> <p>First of all, to declare a variable we need the keyword <b>var</b>. For example, <b>var a</b>; Here, 'a' is the variable. Earlier we have seen variables declared along with their data <a href="/courses/video/5/161/Numbers-int-And-unit.html">types</a>. But here we can't figure out what type of data the variable is going to store. In the same way, Flash also can't understand the data type that is going to be used. In this case, if we assign a <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html">string</a> to the variable a, Flash takes the data as string. In the next line, if we again assign a value to 'a' of data type <a href="/courses/video/4/156/Numbers-As-Our-Second-Variable.html">Number</a>, Flash doesn't show any error but takes the <a href="/courses/video/5/161/Numbers-int-And-unit.html">integer</a> value as well. </p> <p>Here we need to understand one thing :i Flash generates an error <b>only</b> if the assigned data type doesn't match the <b>defined</b> data type of the variable. Above, we didn't define any type for a. Ergo we recommend defining the data type during the declaration of the variable: <b>var a:int;</b> will do it. Now, if you happen to forget a is an integer and write <b>a=&quot;uh oh this is a string!&quot;;</b> Flash will puke! Assigning a type to a variable at definition will make the application run smoothly and it helps us as well while writing the code. You must declare a variable along with its data type and assign the same type of data to it. </p> <h2>Single Command in Single Line</h2> <p>The next thing regarding variable definitions is the necessity to end the declaration with a semicolon. The application considers a line to be ended only if the semicolon is present. If there is no semicolon, Flash considers the next line as part of the first line's code – until that semicolon is reached! Think this could cause an issue of two? A bunch of errors will appear. But if you want to use the same command for declaring two different variables (<b>a:String b:Number;</b>) then the semicolon should be specified at the end of the second statement. These two statements can be written either on one or two lines. Flash considers it to be a single line until the semicolon is reached. Although ActionScript is a forgiving language and many times will automatically end the line on its own, it's good practice to always end a line with a semicolon as other languages aren't as forgiving.</p>

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