Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding additional cards

From: ActionScript 3.0 in Flash CS3 Professional Essential Training

Video: Adding additional cards

In this movie we'll learn to add more cards in a memory game. I'm working in Memory.fla which is in the 9-10 folder inside of the chapter 09 folder along with the rest of the working files. We'll need one more asset for this movie. To grab that asset, go to File - Import - Open External Library. Select Snow.fla in the 9-10 folder and click Open. When the Library window shows up, click and drag Snow from that Library into the Library of your fla file and then close the external Library.

Adding additional cards

In this movie we'll learn to add more cards in a memory game. I'm working in Memory.fla which is in the 9-10 folder inside of the chapter 09 folder along with the rest of the working files. We'll need one more asset for this movie. To grab that asset, go to File - Import - Open External Library. Select Snow.fla in the 9-10 folder and click Open. When the Library window shows up, click and drag Snow from that Library into the Library of your fla file and then close the external Library.

And now we have the asset that we need. Just like when we used the boarder in the blue board for our Memory Game we'll need to export our other card pictures for ActionScript. So let's go to RedBoard in the Library and Right or Control click, and then select Linkage. Check Export for ActionScript, leave the Class name the same, click OK, and then click OK to the other message. Right-click or Control-click Snow in the Library and do the same thing. Choose linkage, check Export for ActionScript and then click OK. CLick OK again and we're ready to use those symbols with ActionScript. Let's go to MemoryGame.as.

After import flash.events.MouseEvent we'll need to do the same thing where we import those classes. So type Return or Enter on your keyboard. Then type import Red with a capital R, Board with a capital B and a semicolon. Go to the next line and type import Snow with a capital S, and then a semicolon. Now we'll need to create variables that will hold that data. In the same area of our code where we declared the other variables, after _currentMatches, press Return or Enter on your keyboard, create a new private variable call this one _redBoard with a capital B, set the datatype to Red with a capital R and then Boarder with a capital B, then a semicolon.

Go to the next line. We'll do the same thing for Snow. Type private var _snow:Snow; The next step is actually generate the card instances. We'll do that by scrolling down and finding our createCards function. Since we'll need to run two more for loops to generate the two new types of card that we have, let's just select both for loops.

So from line 36 all the way down to line 58. Press Cmd or Ctrl+C on your keyboard copy that block of code. Click after the close curly brace, press Enter twice to go down two lines and press Cmd or Ctrl+V on your keyboard and paste the code. Scroll up a little bit to find var i on line 60. select i and then change it to k. We're just going in alphabetical order here i, j, k. Change those three is to three ks, and the three js below to three l's.

Now I'll just need to modify a little bit of code here. Everywhere where it says boarder in the k loop, let's replace that with _redBoard with a capital B. Where it says new Boarder we'll replace with new capital R for Red, and a capital B for Board. I'm going to change it one more time. After setType we need to replace _boarder with _redBoard with a capital B. Now let's do the same thing for Snow. Scroll down a little bit. Change _blueBoard to _snow and then new BlueBoard to new Snow with a capital S.

And then card.setType, change that to _snow as well, Let's save the file by going to File and then Save. Test the movie by pressing Cmd+Return or Ctrl+Enter on your keyboard and notice that we don't really see anything. If you expand the size of your Flash Player window you'll see the other cards. So that's all fine and dandy but we want to create a new row cause we'd have to make our Flash movie ridiculously wide to accommodate that much space. Let's just put the next four cards on a new row.

Close this window out. All we have to do is reset the x to the original x position and then add to the y position. So let's scroll up a little bit until you find the original x and the original y. The original x is 45. Let's select that line of code. Copy it by pressing Cmd or Ctrl+C. Scroll down before the for loop where we have the k variable let's click. We'll paste that code to reset the x to 45 and the x position will be fine, except for they'll layer right over the top of the last four cards. So we just need you adjust the y position. Press Enter, then type _card capital Y, += _card.height + 50; We're spacing the cards out vertically with this code ust as we spaced them out horizontally when we set the card x property in a previous movie.

Go to File, Save. Press Cmd+Return or Ctrl+Enter on your keyboard to test the movie. And there we have two rows, and we can see our snow cards, and our red board cards. And so that is how to create a new row of cards and add cards to your movie. So if you want to add more cards you can add as many as you want by doing the same steps. So everything is great, but if you look in your Output window it says YOU WIN! And we only got two matches. All we need to do is update the total matches variable and we'll be fine. Let's close out the Output window, close out the Flash player window, scroll up and we'll set the total matches on line 26, from two to four Go to File, Save. Test the movie by pressing Cmd+Return or Ctrl+Enter on your keyboard.

And let's get all the matches, and then we win once we get all the matches. And that's that how cards to your Memory Game. By following these same steps you can add as many cards you want.

Show transcript

This video is part of

Expand all | Collapse all
  1. 2m 3s
    1. Introduction
      39s
    2. How to use the exercise files
      1m 24s
  2. 3m 53s
    1. Why you should learn ActionScript 3.0
      52s
    2. Differences from ActionScript 2.0
      1m 56s
    3. Moving beyond Script Assist
      1m 5s
  3. 21m 57s
    1. Communicating to MovieClips
      4m 7s
    2. Modifying MovieClips properties
      7m 0s
    3. Understanding variables
      50s
    4. Setting variable data types
      3m 23s
    5. Using trace statements
      2m 39s
    6. Using comments
      3m 58s
  4. 26m 3s
    1. Understanding functions
      1m 23s
    2. Using functions
      2m 27s
    3. Writing custom functions
      4m 25s
    4. Making a function modular
      11m 50s
    5. Making a function return a value
      5m 58s
  5. 41m 45s
    1. Understanding event types
      1m 28s
    2. Using a listener to catch an event
      3m 14s
    3. Writing event handlers
      6m 56s
    4. Responding to mouse events
      4m 33s
    5. Responding to keyboard events
      5m 45s
    6. Creating a link to a website
      5m 26s
    7. Using the enterframe to create animation
      7m 34s
    8. Using the timer event to control animation
      6m 49s
  6. 44m 32s
    1. Understanding classes
      1m 48s
    2. Writing a custom class
      4m 21s
    3. Extending an existing class
      2m 16s
    4. Understanding methods
      2m 11s
    5. Public vs. private properties and methods
      2m 46s
    6. Bringing a class object to the timeline
      14m 16s
    7. Defining a document class
      8m 13s
    8. Setting up a classpath
      6m 20s
    9. Creating useful classes
      2m 21s
  7. 36m 4s
    1. Understanding conditional statements
      1m 36s
    2. Writing a conditional statement
      4m 40s
    3. Understanding conditional operators
      1m 37s
    4. Using conditional operators
      4m 49s
    5. Setting up alternate conditions
      4m 43s
    6. Writing compound conditions
      4m 22s
    7. Understanding loops
      1m 30s
    8. Creating a code loop
      2m 58s
    9. Using a loop to generate instances of a class
      3m 44s
    10. Placing loop-created instances
      6m 5s
  8. 12m 49s
    1. Understanding the math class
      1m 5s
    2. Using basic math operators
      1m 46s
    3. Generating random numbers
      2m 15s
    4. Using different techniques to round numbers
      7m 43s
  9. 56m 20s
    1. Creating a text field
      3m 27s
    2. Styling a text field
      6m 28s
    3. Capturing data from a text field
      7m 38s
    4. Loading external text
      8m 25s
    5. Scrolling a text field
      5m 14s
    6. Understanding arrays
      9m 48s
    7. Using text and arrays to create a game
      8m 24s
    8. Finishing the text game
      6m 56s
  10. 1h 9m
    1. Storyboarding your application effectively
      3m 13s
    2. Writing a memory card class
      5m 57s
    3. Writing a memory game class
      3m 51s
    4. Adding graphics to cards
      9m 20s
    5. Placing cards
      7m 33s
    6. Detecting matches
      8m 40s
    7. Resetting cards
      4m 53s
    8. Handling incorrect matches
      5m 14s
    9. Determining a win
      3m 51s
    10. Adding additional cards
      6m 47s
    11. Randomizing cards
      10m 17s
  11. 36m 30s
    1. Drawing with code
      8m 12s
    2. Creating a color change
      5m 20s
    3. Generating a random color change
      6m 58s
    4. Animating a color change
      4m 50s
    5. Using filters
      3m 30s
    6. Modifying filter properties
      4m 13s
    7. Animating filters
      3m 27s
  12. 51m 50s
    1. Loading external images and Flash movies
      4m 1s
    2. Communicating to loaded movies
      6m 31s
    3. Loading sound
      4m 6s
    4. Starting and stopping sound
      6m 18s
    5. Pausing and resuming sound
      9m 46s
    6. Managing the volume of sound
      5m 41s
    7. Understanding Flash video connections
      1m 0s
    8. Loading video
      5m 33s
    9. Controlling video playback
      8m 54s
  13. 45m 54s
    1. Overview of creating a drag-and-drop game
      57s
    2. Creating drag-and-drop class
      12m 7s
    3. Detecting collisions
      8m 44s
    4. Responding to collisions
      9m 1s
    5. Detecting a win
      4m 2s
    6. Adding drop shadows
      3m 43s
    7. Randomly placing objects
      7m 20s
  14. 23s
    1. Closing
      23s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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 3.0 in Flash CS3 Professional Essential Training.

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


OK

Course retiring soon

ActionScript 3.0 in Flash CS3 Professional Essential Training will be retired from the lynda.com library on October 10, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion.


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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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 preferencesfrom 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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.