First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: Clinton Montague

The Previous Background Button

Open up the actions panel for the button that you want to change the background to the previous one. It is sensible to use a button on the left to do this but it does not matter. In the actions panel, type in the following script (again, Expert Mode is probably best.)

on (release) {
   a -= 1;
      if(a == 0) {
         a = 4;
         _root.Back.gotoAndPlay ("BG" add a);
      }
      else {
         _root.Back.gotoAndPlay ("BG" add a);
      }
textName=name[a]
}

This script might look horrible but it is actually quite simple if you look at it one step at a time.

  • The on (release) tells Flash to do the instructions that follow when the user releases the mouse button.


  • The a -= 1 is a short and lazy way of writing a = a - 1, they both mean the same thing. If a was 3 for example, Flash would take 1 away from 3, and end up with 2 (3 -= 1 or 3 = 3 - 1 both equal 2).


  • The next bit checks to see IF a is zero, there is no background for zero so a is reset back to 4. I'll tell you what the next bit means in a minute.


  • Incase a is not equal to zero (which it probably will be in most cases), you have to tell Flash to do something else. The variable a does not need to be reset this time becuase there will always be a background for that number. a will never be greater than 4 becuase it is reset to 4, and never less than zero because it is reset when it gets to zero.


  • Now for the nasty looking bit _root.Back.gotoAndPlay. Remeber that when you dragged the background MC from the library to the main stage, you gave it an instance name of Back? this is why. That name enables Flash to find it and do something with it, in this case gotoAndPlay. _root means the root (or highest) level, the . tells Flash that the next bit belongs to that level (the instance name Back is on the top level) and the second . means a property of the Back instace (this one tells Flash to goto and play the bit in the brackets).


  • What Flash has to goto and play is "BG" add a. The labels in the background MC were BG1, BG2, BG3 and BG4, remeber? Well this actionscript tells Flash to go to BG then the add a tells Flash to stuff whatever is stored in the variable a onto the end. The fancy name for this is Concatenating, but don't worry about that. If the number stored in a was 2, then Flash would end up with the line gotoAndPlay ("BG" add 2) which would be gotoAndPlay ("BG2").


  • The last line textName=name[a] does exactly the same as the array in the Variables layer. It does nothing different, it only refreshes it, like a web browser.
» Level Intermediate

Added: 2001-03-14
Rating: 7.82 Votes: 39
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.