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

Displaying the score

From: Flash Professional CS5: Creating a Simple Game for Android Devices

Video: Displaying the score

Once the player has completed the game, you want to go ahead and display the results-- so, how well the player did. And if they've done really well, you want to give them the opportunity to enter their name to be added as the highest scorer. This is all going to be done in this endScreen layer. If I turn that on, you can see this endScreen movie clip. There is its instance name. I'll just double-click it, and in here we have a couple of different elements. First off, we have this high score text field. This is a dynamic text field.

Displaying the score

Once the player has completed the game, you want to go ahead and display the results-- so, how well the player did. And if they've done really well, you want to give them the opportunity to enter their name to be added as the highest scorer. This is all going to be done in this endScreen layer. If I turn that on, you can see this endScreen movie clip. There is its instance name. I'll just double-click it, and in here we have a couple of different elements. First off, we have this high score text field. This is a dynamic text field.

So again, this is selected, and what will be populated in here is how well they've done, their score, what level they got to, information like that. If they've done pretty well, what's going to happen is they're going to have the opportunity to enter in their name in this input text field, and it's known as High-score name. When they click Enter, it's again known as enter_btn. It will actually populate this same dynamic text field with, again, confirmation of how well they did with their name, and then the player can go ahead and play again.

So that's what I want to do, and I'm going to do this all using ActionScript. So, I'm going to go back to scene 1 and I'm going to this Actions layer, that first frame, because right there that's why I'm going to add a code snippet. I encourage you to check out the Code Snippets video if you do not have these code snippets, but what I want to add is this Show Results code snippet. So I'll just double-click on it and it adds that code snippet right here. So I want to move it, but first off, I want to go ahead and review where it's going to go. Okay, so I have this Show Results function, and right in here, there is a couple of things that happen, and I do want to display the high score, but I want to have these first two lines, what they do is they basically hides the text field and the Enter button, so that's what goes on right here.

Go ahead and turn off the enter button and turn off the high-score name. Just by default go ahead and do that. Next step, what this line does is we need to basically enable the play button, so enables the play button. That's what happens right here. Go ahead and make sure the play button works. And what that play button does is if they click on it--and again regardless of how well they do, we want to make sure this play button works-- but when they click on it, it's going to fire off this function called Move Screen Off, which is going to move off the endScreen.

So if you do recall up at the top, this is actually being used for a couple of different things, so I'll just scroll up. moveScreenOff is used for the intro screen as well, but I just want to point out then it's going to go ahead and slide its X position off. And quite frankly, I need to just make sure that it does get reset back to zero, so if you play the game a couple of times, I want to make sure that endScreen always starts in the correct position. So in this endGame function, that line 323 endScreen X position is equal to zero.

If they've played the game a couple of times, you want to make sure that the game always starts out at zero and doesn't appear off to the side, because again, if you play it a second time, you wanted to make sure that it is in the right position. Okay, so again, that's the code currently in here, and what I want to do is I want to go ahead and add the results, so Show Results, and that's where this code snippet comes in right here. I'll just go ahead and take this code snippet, and I'll cut it and paste it right in here at about line 359.

Paste it on there. Right here Show Results, if the score is greater than zero, which is what this says, then go ahead and in that high score text field it says, "Hey you know you made it to whatever level you made it to, with a high score of whatever your high score is that's greater than zero," and this \n just gives it a line break because on the next line it says enter your name below. All right, so right here, come back over here. I'll just add another comment: turns on the enter button and the input text field.

Again, what I turned off up here, I need to go ahead and turn on if they did an okay job, if they've killed the at least one guy, then they get the chance to enter in their name and I make sure the enter button works as well. All right, moving on down, quite frankly, if they did a terrible job, your score of zero is what this really says and does not be zero, so here's where you can add whatever sarcastic comment you want, but know that this is your 'do better next time' line right here within this Else statement right here.

And of course the Enter button, as soon as they click on the Enter button after it gets turned on here, after they click on it, it's going to go ahead and display their results. So it says, "Hey, great job," just confirming how well they did, their name that they've entered in, that text field, what level they made it to, and what their score is. So again, if I can just show you that, after they enter their name, they're going to click Enter that's going to display that information back up in here. And I need to turn those two items off when they do hit the Enter button.

So again, right in here, I'll just add a comment if I could about line 376: hides the enter button just selected and the input text field. That's what happens there. It hides those two, but they can still click on that play button and they will and play the game again. All right, everything seems to look pretty good, but again, I want to go ahead and test this out by playing the game, so let's just test this out real fast.

Click play, and again I just need to destroy at least one of the enemies. Okay, I've destroyed one. All right, so you made it to level 1 with a high score of five. Enter your name below. So again, I can just jump in here, enter in my name in this input text field.

This Enter button, when I click on it, it will display my results, as well as my name, and these two items will disappear. Sure enough, that happens "Great job, Paul! You made it level 1 with a high score of 5. All right, so I have this working out great. You can see that it's populating the high score screen, but what I want to do next is I want to go ahead and save these results as my current high score. And each time I play the game, I want to go ahead and try to beat the previous high score, but again that's going to happen in the next lesson.

Show transcript

This video is part of

Expand all | Collapse all
  1. 1m 48s
    1. Welcome
      1m 0s
    2. Using the exercise files
      48s
  2. 7m 16s
    1. Understanding the user
      4m 2s
    2. Flash content on Android devices
      3m 14s
  3. 17m 28s
    1. Reviewing the game
      1m 50s
    2. Creating a file in Device Central
      5m 39s
    3. Reviewing the game structure
      8m 23s
    4. Adding code snippets
      1m 36s
  4. 36m 13s
    1. Animating the intro screen
      8m 13s
    2. Moving the player
      8m 13s
    3. Adding enemies
      6m 49s
    4. Adding movement
      4m 16s
    5. Adding chance and randomness
      8m 42s
  5. 34m 30s
    1. Adding lasers
      8m 14s
    2. Detecting collisions
      7m 57s
    3. Adding explosions
      6m 26s
    4. Removing assets from the stage
      8m 50s
    5. Adding audio
      3m 3s
  6. 33m 12s
    1. Adding scoring and levels
      7m 41s
    2. Subtracting lives and ending the game
      4m 26s
    3. Creating a results screen
      5m 8s
    4. Displaying the score
      6m 57s
    5. Saving and loading game results
      9m 0s
  7. 17m 14s
    1. Detecting movement with the Accelerometer
      6m 39s
    2. Using the swipe gesture
      4m 42s
    3. Using hardware keys
      5m 53s
  8. 23m 18s
    1. Handling exits and idle mode
      3m 31s
    2. Handling activation and deactivation
      6m 14s
    3. Optimizing graphics
      7m 14s
    4. Optimizing ActionScript
      6m 19s
  9. 34m 41s
    1. Creating the application files
      8m 23s
    2. Creating the app (Mac)
      5m 5s
    3. Creating the app (PC)
      7m 19s
    4. Publishing to an Android device (Mac)
      7m 7s
    5. Publishing to an Android device (PC)
      6m 47s
  10. 8m 56s
    1. Uploading to the Android market
      7m 7s
    2. Downloading from the Android market
      1m 49s
  11. 1m 22s
    1. Next steps
      1m 22s

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.

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 Flash Professional CS5: Creating a Simple Game for Android Devices.

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?

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.