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

Mixing Strings and Numbers

<p>When working with <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html">strings</a> and <a href="/courses/video/4/156/Numbers-As-Our-Second-Variable.html">numbers</a> it's important to prevent Flash from automatically converting data so you'll not be automatically confused. To keep things simple it's best for you to manage your conversions on your own. Let's learn why and how.</p> <p>We have seen how to add two strings together using Flash, after viewing the <a href="/courses/video/5/36/Addition.html">previous video</a>. As programmers, we need to learn all the possible operations that take place in our domain (Flash.) So we have to be careful while dealing with numbers and strings together. There are occasions where we need to <a href="/courses/video/5/36/Addition.html">add</a> a number to a string or vice versa, so now we'll learn all the possible ways to mix stings and numbers together.</p> <p>As usual, this type of addition is performed using the '+' <a href="/course/basics/operators">operator</a>. We can type the string and then add a number to it, for example</p> <p><i>trace('Flash' + 1);</i></p> <p>This will make the compiler assume 'Flash' is a String and 1 is a Character. Addition is therefore performed: the output is the String &quot;Flash1&quot;. The process is the same even if the values are interchanged: for instance, <b>trace(1 + 'Flash'.)</b> Here the output will be &quot;1Flash&quot; (also considered as a string.) We can add any number to a string without putting the number in double quotes.</p> <p>There is a sneaky problem here! When we add a string and a number, the application assumes the number is a character and then adds (concatenates) it to the String. This might lead to problems when we don't really want the application to take the number as a character. It becomes more complicated when two numbers are added together and one of them is in double quotes: <b>trace(&quot;20&quot;+10.)</b> Flash assumes both the numbers as strings and combines them instead of adding the two: here, you get &quot;2010&quot; as your string result.</p> <p>Moreover, when part of the equation has several numbers and part of it has a string, then addition is performed for some parts and the string part is combined to that result. For example, if we take <b>trace(1 + 1 + 3 +'2')</b>, we expect the result as 7. But we now know the result is altered due to those double quotes: we expect the result to be the combination of all the <b>numbers</b>, 1+1+3 added to the <b>string &quot;2&quot;</b>. Sure enough, Flash adds the first three numbers (not in double quotes) resulting in the sum equal to 5. Now, this <a href="/courses/video/5/161/Numbers-int-And-unit.html">integer</a> is combined to the string &quot;2'' which yields &quot;52&quot; as output (also considered as string.)</p> <p>It's very difficult to understand whether the number is considered as integer or string. However, effort, concentration and practice will make any task easier. The good news is that a few exams added to all that will do the trick – plus perhaps an <a href=" http://blog.everythingfla.com/contact">email</a> or two to us if you get lost!</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