ActionScript 2.0 Essential Training
Illustration by Don Barnett

associative arrays


From:

ActionScript 2.0 Essential Training

with Joey Lott

Video: associative arrays

Now we just talked about arrays. And because we just talked about arrays I want to talk to you about something else that's very closely related. And that's something called an Associative Array. When we use an array object then we're using the Array class. And the Array class gives us the opportunity to order our data using integer indexes. Integers are whole numbers. So, 0, 1, 2, 3, 4, 5, et cetera. Now an Associative Array doesn't necessarily have to be created using the Array class.
Expand all | Collapse all
  1. 45s
    1. welcome
      45s
  2. 7m 52s
    1. ActionScript and the environment
      1m 54s
    2. working in the environment
      5m 58s
  3. 1h 41m
    1. understanding datatypes and variables
      12m 28s
    2. exercise: variables
      6m 48s
    3. expressions and operators
      6m 4s
    4. using if
      10m 58s
    5. exercise: if
      3m 9s
    6. using switch
      8m 1s
    7. exercise: switch
      3m 10s
    8. using for
      12m 5s
    9. exercise: for
      3m 27s
    10. working with functions 1
      5m 19s
    11. working with functions 2
      7m 15s
    12. working with functions 3
      3m 22s
    13. working with functions 4
      5m 14s
    14. exercise: functions
      3m 6s
    15. using setInterval
      8m 24s
    16. exercise: setInterval
      2m 41s
  4. 27m 8s
    1. objects
      3m 48s
    2. arrays
      13m 27s
    3. associative arrays
      9m 53s
  5. 49m 54s
    1. movie clips and buttons
      3m 14s
    2. movie clip addressing
      6m 47s
    3. event handler methods
      10m 57s
    4. basic animation effects
      5m 9s
    5. exercise: slideshow 1
      6m 31s
    6. exercise: slideshow 2
      4m 59s
    7. draggable movie clips
      7m 37s
    8. performing hit tests
      4m 40s
  6. 1h 11m
    1. introducing attachMovie
      13m 27s
    2. exercise: windows 1
      6m 19s
    3. exercise: windows 2
      5m 21s
    4. exercise: windows 3
      3m 51s
    5. exercise: windows 4
      6m 40s
    6. loading movie clip content
      10m 56s
    7. adding scripted masks
      5m 37s
    8. exercise: scripted masks 1
      11m 17s
    9. exercise: scripted masks 2
      5m 11s
    10. exercise: scripted masks 3
      2m 27s
  7. 2h 26m
    1. dynamic text fields
      13m 36s
    2. exercise: article viewer 1
      8m 33s
    3. formatting text
      10m 19s
    4. making HTML formatted text
      5m 17s
    5. loading text
      5m 52s
    6. exercise: article viewer 2
      6m 22s
    7. scrolling text
      10m 57s
    8. exercise: article viewer 3
      8m 31s
    9. cascading style sheets 1
      11m 37s
    10. cascading style sheets 2
      6m 3s
    11. exercise: article viewer 4
      5m 38s
    12. making input fields
      5m 51s
    13. making password fields
      10m 2s
    14. exercise: article viewer 5
      20m 54s
    15. loading variables
      7m 40s
    16. exercise: article viewer 6
      8m 55s
  8. 52m 33s
    1. introducing components
      1m 54s
    2. the button component
      10m 25s
    3. combo box and list
      9m 24s
    4. multiple selections for a list
      3m 19s
    5. the checkbox component
      4m 14s
    6. radio buttons
      5m 39s
    7. exercise: quiz form 1
      10m 11s
    8. styles for components
      5m 22s
    9. exercise: quiz form 2
      2m 5s
  9. 1h 14m
    1. creating and attaching sound
      6m 8s
    2. loading sound
      6m 36s
    3. load progress
      7m 25s
    4. start, stop and pause
      4m 46s
    5. setting the volume
      6m 16s
    6. playback
      5m 38s
    7. playback dragging
      4m 50s
    8. exercise: sound 1
      5m 53s
    9. exercise: sound 2
      5m 11s
    10. exercise: sound 3
      2m 54s
    11. exercise: sound 4
      3m 47s
    12. exercise: sound 5
      5m 14s
    13. exercise: sound 6
      9m 46s
  10. 57m 51s
    1. introduction to video
      2m 46s
    2. creating a video symbol
      6m 26s
    3. attaching video to the stage
      3m 44s
    4. exercise: video 1
      9m 8s
    5. play and pause
      3m 32s
    6. exercise: video 2
      2m 18s
    7. video progress
      2m 37s
    8. exercise: video 3
      3m 36s
    9. audio and video
      4m 23s
    10. exercise: video 4
      6m 41s
    11. looping playback
      4m 51s
    12. exercise: video 5
      2m 33s
    13. exercise: video 6
      5m 16s
  11. 9s
    1. goodbye
      9s

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
please wait ...
Watch the Online Video Course ActionScript 2.0 Essential Training
9h 50m Beginner Jan 29, 2004

Viewers: in countries Watching now:

ActionScript 2.0 is a powerful scripting language that allows you to create complex and highly interactive Flash applications. In ActionScript 2.0 Essential Training, Joey Lott will teach you the essential skills and reveal the insider information you need to begin developing Flash applications. The training begins with an overview of programming terms and concepts used in ActionScript such as datatypes, variables, expressions and operators, switch statements, arrays, functions, etc., and then quickly moves on to show apply the concepts using practical examples. While this training title was recorded in the Flash MX 2004 interface, it is appropriate for users of Flash 8 as well. Exercise files accompany the tutorial, allowing you to follow along and learn at your own pace.

Note: This product was previously named Learning ActionScript 2.0 in Flash MX 2004

Topics include:
  • The work environment
  • Datatypes and variables
  • Expressions
  • Variables
  • Objects
  • Arrays
  • Movie clips
  • Buttons
  • CSS in Flash
  • Sound
  • Video in Flash
Subjects:
Developer Web
Software:
ActionScript Flash Professional
Author:
Joey Lott

associative arrays

Now we just talked about arrays. And because we just talked about arrays I want to talk to you about something else that's very closely related. And that's something called an Associative Array. When we use an array object then we're using the Array class. And the Array class gives us the opportunity to order our data using integer indexes. Integers are whole numbers. So, 0, 1, 2, 3, 4, 5, et cetera. Now an Associative Array doesn't necessarily have to be created using the Array class.

In fact, most of the time we're going to create Associative Arrays using the Object class. That's object with a capital O. Object is the base class - sort of the most fundamental class upon which all other classes are based. Typically, we'll use the Object class to create an Associative Array. What an Associative Array does is it helps you to organize your data. Instead of using an integer index, we use a string index.

And we refer to those string indices as keys. An array created using the Array class like we just talked about in the previous lesson, is useful when you want to create some structure to your data. That way you can sort your data and organize it in lots of different ways. Using an Associative Array is helpful when you want to group some related data, but they don't necessarily have any order. Instead they have particular significances. And what I mean by that is, for example, you might have some information about a company.

And you would have the employees of your company. You might have John, and Sue, and Fred. And each of these people who are employees have different titles. Maybe one's the president and one's the CEO, and one's the CTO. So they don't necessarily have a particular order. But they do have particular significance. And they're all related. So we could use an Associative Array in order to group that information. And then we could give each of the pieces of data a key in order to be able to reference it.

And the key in those cases would be president, or CEO, or CTO. So let's take a look at a code example of this. I'm going to open the Actions panel and I'm going to instantiate an Associative Array. So I am going use the var keyword, of course, because I want to declare a variable in order to store my Associative Array. And I'll call it oEmployees. And I'll define that as being an Object datatype.

And then I am going to use the Object constructor - that's object with a capital O - in a new statement. So I'll type new Object. Now, one thing I want to talk about before we move on is we have the Object with a capital O. And because ActionScript in MX 2004 is case sensitive, then if we were to use a lowercase o, that's not the same thing. When we use the lowercase o, it's just simply a term we use to describe a generic instance of a class.

But the Object with a capital O is a specific class name. And you'll notice that when I type it with a capital O, then I get code syntax coloring, and that indicates that that is a keyword. And that is the Object class. And that's differentiated from object with a lowercase o, which is a general term that we use to describe instances of classes. Whether that be an instance of the Array class or a MovieClip class, or any of the other classes that we'll discuss throughout the remaining lessons of this title.

So in order to create our simple Associative Array, we're creating an instance of the Object class. In order to add data to my Associative Array I am going to use dot syntax. There are two alternative ways that you can do this. And we're going to start with dot syntax. In order to do that, I am going to type the name of my Associative Array. Which is oEmployees. And then I use dot. And then I follow that with the key. And the key is something that I get to make up.

And in this case I'm going call one of them president. And then I use an assignment operator. And I assign to that the value of - let's say that "Sue" is the president of this particular company. And then I can add another element to my Associative Array. And let's say that "John" is the CTO of my company.

And let's add one more. And let's say that "Sarah" is the CEO of this company. So I have created an Associative Array that has three elements. And each element has a key. The keys are president, cto, and ceo. And then I have the values that I have associated with those keys of Sue, John, and Sarah. Now, if I want to be able to retrieve those values, then I can use the dot syntax in a situation such as within a trace statement.

If I wanted to output the value, then I could use, as an example, oEmployees.president. And when I test the movie, I'll see that Sue is displayed in the Output panel. Now there's another way that we can reference the elements of the array. And that is using array access notation. So let's take a look at that, and then we'll compare and contrast the benefits of each of these two techniques.

So using array access notation, we still start with the name of the Associative Array. Which is oEmployees, in this case. And then I use the square brackets in order to specify the key. And then the key is going to be specified as a string. So let's create one more element in our Associative Array. And we'll use the key of "cfo". And let's assign that a value of "Arun".

And then if I want, I can also reference that value, and we could use a trace statement to illustrate this. I can also reference the value using array access notation. So I can type oEmployees and use the square brackets. When I test the movie I will see that Arun is displayed in the Output panel. I can additionally, if I wanted, I could also reference the same element using dot syntax.

So they're interchangeable for the most part. And the same would be true if I wanted to reference the CEO using array access notation. So why would I use one over the other? It's a good question. The benefit that the array access notation has over the dot notation is that the key is specified as a string. And this becomes really valuable when we're wanting to use things that are more dynamic. For example, if our Associative Array has keys that are determined more programmatically, or if we don't know them to hardcode them at the time we're writing our code, then we want to use the array access notation because then we can use a variable as the key.

Here's an example. If I create a variable called sKey and I assign that a value of "ceo", then I can reference the element that corresponds in my Associative Array using the sKey variable inside of the square brackets. In order to get the bigger picture for this, I am going to tell you this. All objects created from all classes in ActionScripts can be treated as Associative Arrays, this becomes particularly valuable when we're working with, for instance, movie clips.

And then what happens is a lot of people often times want to know how they can reference a movie clip dynamically. And what they can do is use Array Access notation in order to reference the movie clip. And we'll get a chance to see some of that in action in the movie clip section of this title. All right. Objects and arrays. They can seem a little bit complex when you're first starting with them. But you can definitely pat yourself on the back; it's an advanced topic, so you're definitely moving along on the ActionScript path.

We're going to be using a lot of these concepts more in the later exercises, so you'll get a chance to practice with them. One thing that I need to tell you, though, is it's important that you just be willing to have an open mind and try these things. There's something to be said for "Slow and steady wins the race." That's true. But you also need to be willing to take the steps. So we're going to be walking through a lot of exercises together. I would encourage you to practice with them. If there's any sticking point, then try it again. And you'll always find the finished and commented versions of all the exercises to use for reference if there's any point that you're uncertain about.

There are currently no FAQs about ActionScript 2.0 Essential Training.

 
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.

Join now Already a member? Log in

* 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

Congratulations

You have completed ActionScript 2.0 Essential Training.

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


OK
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 lynda.com 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 lynda.com 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 lynda.com 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 lynda.com.

Sign up and receive emails about lynda.com 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.