Viewers: in countries Watching now:
In ActionScript 3.0 in Flash Professional CS5 Essential Training, Todd Perkins shows Flash designers how to incorporate ActionScript code into their projects and create interactive presentations and applications. The course includes a review of ActionScript language basics and the object-oriented programming (OOP) methodology, a tour of those Flash Professional CS5 features designed for developers, such as code hinting and the Code Snippets panel, and instructions on interacting with objects in the Library and placing code on the Timeline. Exercise files are included with the course.
When you're working with large amounts of data, it is crucial to stay organized so that data can easily be accessed and utilized. Using arrays and vectors, it is easy to organize large amounts of data. Let's start by looking at an array. Let's say you wanted to load 50 different thumbnail images into a slideshow. Now it'd be nice to have some organized way to store all those image names, right? Well, with an array, you can do that.
To create an array, type var, then a space, then name your array. I usually name my array something plural, so thumbnails, for example. I'd say these represent thumbnail images that you would load into Flash. So thumbnails: and now remember, you're telling Flash what type of data the variable is, and an array is an array. So type capital A and begin to type Array, and you'll see it selected in the code hinting area, and you could just double-click that or press Enter on your keyboard, and Flash will finish it for you.
And then type space = space, and there are actually several different ways that you can create an array. I can type new Array, capital A, and Flash will create the array in memory. And then I can go to the next line, and every time I want to add something to the array, I can type thumbnails.push. This adds an item into the array, so I'll just double-click push.
Notice it's an action word, so it's like a command, like a function. And inside the parentheses, I put whatever object I want to add. So in quotes, I would put something like image1.jpg. This isn't actually representing a real image. I'm just giving an example. So I'll close out the parentheses and type a semicolon. So if I wanted to add more images, I can just select this line of code, copy it with Command or Ctrl+C, go to the next line, paste with Command or Ctrl+V, and then repeat, and then change that to image1, image2, image3, image4.
That's one way to create an array. I'm going to delete all these lines at the bottom now, and look at a shorthand way to do all this. Inside of the parentheses, when you create the array, that's the new Array parentheses, you can type comma-separated values. Type image1.jpg in quotes, and then a comma, a space, and then in quotes you can type image2.jpg, and so on. The last way to create an array is a really shorthand way, which just involves square brackets.
So I can replace new Array and the open parenthesis with an open square bracket. That's right under the curly brace, so if you don't hold Shift and you press Curly Brace key then you'll get square bracket. Now I'll move to the right parenthesis and replace that with a right square bracket. So I've created an array, and now I have an organized way to store my data. Now I'm not going to type in all 50 images here, but you get the point. Now let's say you wanted to access one of the elements in the array.
So I store all my data in this array, a big list, and then I want to pull out one of the elements in it. To do that, we're going to use something called array access notation, which sounds a lot more complicated than it is. All it is is square brackets. So go to the next line, type a trace statement, and in the parentheses type 'thumbnails' and then some square brackets, and inside of the square brackets, type the number of the thumbnail you want to access.
Now, arrays start at number zero, so image1.jpg would be at index zero of the array; image2.jpg would be at index 1; the next one would be at index 2; and then 3, and 4, and so on. So to access the first piece of data in the array I type a zero inside of the square brackets, and then I test the movie, and you can see I have access to that data. So right now that may not seem extremely useful, but you can imagine how much easier it would be to stay organized when you have large amounts of data.
You put them into an array, and you can access the data using a simple array access notation. Another way to hold this of data is called a vector. Because vectors are Flash Player 10 only, and the syntax is drastically different from an array and anything else we'll be doing in this title, I'm going to focus on arrays for this title. But typically if you're using Flash Player 10, a vector is the more optimized option.
Here is how to create a vector. Type the word 'var' and then a space and the name of the vector. I'm just going to call this 'v' type a colon to declare the data type and set it as a vector with capital V. And one of the differences between a vector and an array is that a vector can only hold one type of data that you specify. An array can hold numbers and strings at the same time, and a vector can only hold all strings, or all numbers, or all any other data type, but they all have to be the same data type in a vector.
That's part of what keeps them optimized. So we're going to tell Flash that this vector will only contain strings. To do that, type a dot after Vector and then a less than sign, and in there, type a capital S, for String. So start to type String. Once it's highlighted, press Return and then close out with a greater than sign. This syntax here, the dot, less than, greater than sign, is something we're really not going to be working with in this title, which is, again, why I'm going to work with array in this title.
So after that, type space, then a new, space, Vector, capital V, and you'll see that
Find answers to the most frequently asked questions about ActionScript 3.0 in Flash Professional CS5 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.