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

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 (a term we will revisit in the future.)

After seeing the previous video, you might get confused about why we used a number in double quotes, wanting it to behave as string. We sometimes need the number to behave as string when the number is to be attached along with strings. This is rare when working in Flash but becomes very common when working with external teams or back-end code. Most of the time, we don't specify a number as string but it may appear in double quotes or single quotes if it's downloaded from some other source or from the server directly.

In these cases, we have the number as string but we want it to be an integer for addition. In this instance, Flash does some automatic conversion. If you leave the conversion for the application, it will be invisible to you %u2013 you might convert something without wanting to or knowing about it. This is because basically Flash tries to convert everything into strings when one string is added to a number. So to convert the number within quotes into an integer, we make use of the keyword Number. We enclose the number along with the double quotes in a bracket and type Number before it. This converts the data inside the bracket from string to integer. Hence, both the numbers are considered as numbers thereafter and addition of the numbers is performed accordingly.

A simple example will let you know how exactly it's done. If the line from the source is trace(2 '3'), the output is 23 %u2013 but we want it to be the sum of those two numbers. A few modifications are done as said earlier such as trace(2 Number('3')). Therefore, when the program is now compiled, the application adds both numbers and gives the output as 5 which is the preferred answer (mathematically correct) for most users. We therefore recommend not to allow Flash to perform automatic conversions; instead use these various techniques and keywords to make the conversions according to our will.

'I love being Prime'

Have a question but don't want to ask it publicly? If you're a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

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