ActionScript 3.0 in Flash Professional CS5 Essential Training
Illustration by John Hersey

Creating arrays and vectors


ActionScript 3.0 in Flash Professional CS5 Essential Training

with Todd Perkins

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Creating arrays and vectors

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.
Expand all | Collapse all
  1. 3m 22s
    1. Welcome
      1m 23s
    2. Using the exercise files
      1m 17s
    3. Using the function keys
  2. 23m 38s
    1. Adjusting preferences for ActionScript fonts, colors, and formatting
      3m 25s
    2. Changing Flash Player and ActionScript versions in the Publish settings
      1m 35s
    3. Reading and solving errors through the Compiler Errors window
      2m 49s
    4. Using the Actions panel buttons to add and remove comments
      2m 33s
    5. Using the Actions panel to format code
      1m 49s
    6. Using the Actions panel Toolbox
      2m 4s
    7. Seldom-used but helpful functions of the Actions panel
      3m 14s
    8. Understanding code hinting
      2m 3s
    9. Reviewing the Code Snippets panel
      3m 7s
    10. Using help
  3. 45m 50s
    1. Understanding how ActionScript 3.0 code is processed in the Flash Player
      3m 22s
    2. Understanding variables
      4m 56s
    3. Understanding functions
      9m 1s
    4. Understanding events and event listeners
      5m 47s
    5. Working with conditional statements
      9m 49s
    6. Creating arrays and vectors
      6m 50s
    7. Using the For command to create a loop
      6m 5s
  4. 49m 9s
    1. Reviewing the display list
      3m 0s
    2. Understanding instances referenced through ActionScript
      2m 27s
    3. Using dot syntax to modify properties in an instance
      3m 25s
    4. Placing objects at the center of the stage
      4m 2s
    5. Placing objects at the edges of the stage
      5m 53s
    6. Using the methods of an instance
      3m 44s
    7. Accessing the parents, children, and grandchildren of objects
      5m 50s
    8. Creating instances from Library movie clips using ActionScript
      4m 23s
    9. Adding objects to the stage and changing parents with the addChild method
      5m 45s
    10. Removing objects from the stage with the removeChild method
      4m 17s
    11. Using the numChildren property to loop through a container's child objects
      3m 17s
    12. Using the getChildByName method
      3m 6s
  5. 56m 20s
    1. Understanding timelines
      4m 15s
    2. Using common timeline navigation methods
      5m 34s
    3. Using the currentFrame and totalFrames properties
      8m 2s
    4. Controlling the timeline of an instance
      6m 41s
    5. Detecting and navigating frame labels with ActionScript
      7m 57s
    6. Solving problems when timelines and ActionScript animation collide
      4m 16s
    7. Condensing a multi-frame timeline into one frame
      8m 33s
    8. Creating a simple slide presentation app in the timeline
      7m 51s
    9. Using one event handler with multiple buttons
      3m 11s
  6. 36m 5s
    1. Creating a class using Flash templates
      4m 43s
    2. Setting a document class
      6m 51s
    3. Preparing a class to be connected to a symbol
      4m 31s
    4. Using the Symbol Properties menu to connect a symbol to a class
      4m 55s
    5. Resolving problems with instances in a linked class
      7m 53s
    6. Understanding packages
      3m 17s
    7. Working with ActionScript source paths
      3m 55s
  7. 44m 32s
    1. Viewing the finished game
    2. Viewing the FLA file
      2m 9s
    3. Creating the DragDrop and Map classes
      2m 51s
    4. Linking the draggable class to Library symbols
      2m 47s
    5. Adding drag-and-drop functionality
      3m 38s
    6. Saving and resetting an object's position
      3m 33s
    7. Giving a target drop object to the draggable objects
      13m 16s
    8. Showing a Win screen
      7m 3s
    9. Resetting the game
      8m 24s
  8. 29m 6s
    1. Loading bitmap images from the Library
      4m 6s
    2. Loading bitmap images from external files
      5m 22s
    3. Adding mouse functionality to bitmap images
      3m 31s
    4. Using a loop to load multiple images
      6m 14s
    5. Creating a simple slideshow
      8m 37s
    6. Using Flash Player 10 color management
      1m 16s
  9. 27m 13s
    1. Loading an external SWF
      4m 14s
    2. Running ActionScript code in an external SWF from its parent
      5m 30s
    3. Running parent code in a child SWF
      5m 7s
    4. Creating a timeline-based preloader to load an external SWF file
      5m 3s
    5. Displaying playback progress of a loaded SWF file
      7m 19s
  10. 40m 10s
    1. Creating plain text files
      2m 8s
    2. Loading text from an external text file
      6m 26s
    3. Loading multiple text files
      6m 43s
    4. Rendering simple HTML in a text field
      5m 51s
    5. Creating a scroll bar for a text field
      5m 29s
    6. Scrolling a text field
      4m 59s
    7. Scrolling movie clips and other objects using masks
      5m 42s
    8. Modifying TLF text properties through ActionScript
      2m 52s
  11. 23m 40s
    1. Reviewing XML and E4X syntax
      3m 29s
    2. Loading an XML file
      3m 26s
    3. Using dot syntax to access XML data
      4m 2s
    4. Using XML data to populate a DataGrid component
      7m 4s
    5. Using XML data to load image files
      5m 39s
  12. 23m 33s
    1. Loading audio from the Library
      1m 41s
    2. Loading audio from external files
      3m 41s
    3. Playing, pausing, and stopping sounds
      5m 39s
    4. Muting all audio with the SoundMixer.stopAll method
      1m 28s
    5. Tracking load progress
      2m 38s
    6. Displaying sound position
      5m 5s
    7. Adjusting volume
      3m 21s
  13. 19m 54s
    1. Touring the FLA file
      5m 57s
    2. Controlling video playing and pausing with ActionScript
      1m 56s
    3. Working with ActionScript cue points to add closed captioning
      3m 35s
    4. Displaying video playback position
      3m 44s
    5. Adjusting video volume
      4m 42s
  14. 5m 32s
    1. Using new code snippets for AIR and mobile
      1m 13s
    2. Viewing the new code snippets HUD
      1m 17s
    3. Loading assets with the new ProLoader class
      1m 8s
    4. Understanding Flash Player premium features
      1m 54s
  15. 16s
    1. Goodbye

please wait ...
Watch the Online Video Course ActionScript 3.0 in Flash Professional CS5 Essential Training
7h 8m Beginner Oct 21, 2010 Updated May 23, 2012

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.

Topics include:
  • Understanding the building blocks of ActionScript
  • Working with the display list
  • Using dot syntax
  • Navigating the Timeline
  • Creating document classes
  • Linking classes to Library objects
  • Adding drag/drop functionality to objects
  • Creating a slide show
  • Loading and running code in an external SWF
  • Working with text
  • Accessing XML data
  • Playing audio and video with ActionScript
Developer Web
ActionScript Flash Professional
Todd Perkins

Creating arrays and vectors

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 Vector. is highlighted, so I'm just going to double-click that and then some parentheses and a semicolon. So that's how to create a vector that'll hold a string. Again, we're not going to be diving too deep into vectors in this title, but it is more optimized, and it's Flash Player 10 only, so if you want to use a Vector, you can look up the vector class in Flash help. The main thing I want you to take away is that arrays and vectors allow you to organize data for easy access.

Find answers to the most frequently asked questions about ActionScript 3.0 in Flash Professional CS5 Essential Training .

Expand all | Collapse all
please wait ...
Q: Will the exercise files for this course work with Flash CS6?
A: Yes, the code should work fine. The language has not changed since CS5.
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.

Mark all as unwatched Cancel


You have completed ActionScript 3.0 in Flash Professional CS5 Essential Training.

Return to your organization's learning portal to continue training, or close this page.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.