Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 102042 Viewers
61 Video lessons · 88764 Viewers
71 Video lessons · 72577 Viewers
56 Video lessons · 104221 Viewers
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.
Your file was successfully uploaded.