Learn how to assign data type to an object in Adobe Flash Lite 2.1.


More DIY videos at 5min.com

Video Transcription

So Action Script 2 allows us to specify in advance the type of data that any variable is supposed to contain. So, that might be a string or a number or a Boolean or something like that. Data type objects is base practice because it helps us cutout some programming areas and also it gives us core heading in our Actions Panel and we will see that a little later on when we start actually typing out some code. All data types and Actions Script are actually class names. This is an idea that we will actually discussing a bit later on, but for now, this just means that our data types will always begin with the capital letter and that will be describing the type of category of object that they belong too. So a data type is specified immediately after a new declared identifier, whether that is a variable name or a name of an object and it separated from the variable name with the colon. For example, we start of declaring the variable name using the var statement, then we type the variable name then the colon and we tell what data type the variable name will be. Then, we just use the equal sign and give it a default value. There are three core data types, a string, a number and a Boolean. So let us open up our first project file for this lesson and get coding with some date types. I am going to go up to the file and open command and look through our project files. Now, I have open up the string to lesson 2. But if I browse the system, you can see that I am looking where the project files were installed, part one, lesson 2 and we are going to open scavengerhunt_1_rar. Okay, so this is the mobile game that we are going to build in yet over the coming lessons. As the name suggest, it is a bit of scavenger hunt, so we are going to be using it to find clues and this is going to includes sounds and video clues as well as showing XML data it is going to be showing text clues, video and sound clues and it is really going to be example for us to show the full power Flash Light 2.1 but we will get to all off that in a minute. So what we are going to do first is declare some instance name for some objects and give them a data type. Let us select the first action script frame. So as you can see we have got some actions script already in place and this is the same actions script that we saw with our mobile template. So underneath the decorations comment block, we are going to start adding some code. The first thing we are going to do is declare a Variable. So as we saw in our example, we start off by using the var statement. This first variable that we are going to look for is going to be a Boolean but first we have to give an instance name. So this one is going to bHasMP3, and we will see the significance of that instance name soon. After we have identified the variable name, we separate it with the colon and then we are gong to tell what data type we want this variable to be. You can see when we type the colon Flash gives us some core heeding. It just giving us some short cuts as to what we might want to do next. In this case, we are going to set a data type and this one is going to be a Boolean. So we simply type Boolean or we could have chosen it from the code heading list. We are going to end this line with a semicolon and there we declare that variable. So I am going to declare second variable now too. This one is going to be called sHas4Way. Again, we separate it with the colon and this time we are going to set it as a string. So our first variable is expecting to be either true or false. The second Variable is always expected to be a string, so a list of characters. And we will see what happens if that gets jumbled up a bit later. Just say you know, Boolean types are true or false. Literally, those two words, true or false are the key word mutual in Action script 2. So a Variable declare to hold the Boolean data type can only have the value true or false assign to it so there is no quite answer, true or false, they are build into the language. With this String data type it is just a list of characters, any characters so a word or even a whole sentence or paragraph is just a string. You could also have numbers in those characters but if we enclose in quotes, either single quotes or double quotes, it is going to be referenced as a string. If you forget to use the quotes Flash is going to think you are trying to set something else and you probably going to get some action script errors. Before we go on let us save our file. I am going to save as and we are going to call this scavengerHunt_1. Let us just type the _raw at and save that in the same location. Great!