• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Lesson 26. Using a List Database > Changing Directions

Changing Directions

Clicking the direction letters still produces a script error because you haven't written the handler yet. You may recall from the previous lesson that cast member scripts already exist for most of the direction letters. These scripts were provided to give you a jump-start on this project. Now you will take a look at one of those scripts to see how it works.

1.
Select cast member 30. Then click the Script button.

The handler looks like this:

on mouseUp
  SetDirection("n",10)
end

This handler sends the letter of the direction as the first parameter in the handler ("n") and the channel number of the sprite that was clicked as the second parameter (10). The script that is called, SetDirection, is the one you will create next in the movie script.

2.
Close the Script window.

3.
Open the movie script and add the lines shown in bold:

global gLocationList, gCurrentView       --Declare these as global variables.

on startMovie                            --At the start of the movie, do the following:
  CreateLocationList                     --Run this handler to create the location list.
  gCurrentView = "vict.n"                --Set the northern view of Victoria as the default.
end

on CreateLocationList                   --startMovie calls this handler.
  gLocationList = [:]                   --Declare an empty property list.
  setaProp(gLocationList, item 1 of line 1 of field "Location codes",}
  item 2 of line 1 of field "Location codes")
                                        --Insert the first item in line 1 of the field into
                                        --the property list, gLocationList.
                                        --This is the property.
                                        --Insert the second item of
                                        --the field into the list as the data
                                        --associated with that property.
  setaProp(gLocationList, item 1 of line 2 of field "Location codes",}
  item 2 of line 2 of field "Location codes")
                                        --Insert the first item in line 2 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list as the data
                                        --associated with that property.
  setaProp(gLocationList, item 1 of line 3 of field "Location codes",}
  item 2 of line 3 of field "Location codes")
                                        --Insert the first item in line 3 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
  setaProp(gLocationList, item 1 of line 4 of field "Location codes",}
  item 2 of line 4 of field "Location codes")
                                        --Insert the first item in line 4 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
  setaProp(gLocationList, item 1 of line 5 of field "Location codes",}
  item 2 of line 5 of field "Location codes")
                                        --Insert the first item in line 5 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
end
on SetPlace thePlaceName, theSprite
                                        --When a location name is clicked, the name
                                        --of the location and the sprite number are
                                        --sent as parameters.
  newView = getaProp(gLocationList, thePlaceName)
                                        --Get the data associated with thePlaceName
                                        --in the gLocationList property list. Then set
                                        --newView to that data. The data is a code
                                        --for a particular location.
  oldDirection = (gCurrentView).char[(gCurrentView).chars.count]
                                        --Get the last character of gCurrentView. This
                                        --will be a direction letter. Then set
                                        --oldDirection to that letter.
  gCurrentView = newView&"."&oldDirection
                                        --Concatenate newView and oldDirection and
                                        --place a period between them. This results
                                        --in the name of a cast member.
                                        --Set gCurrentView to this value.
  sprite(1).memberNum = member (gCurrentView).number
                                        --Switch the cast member assigned to
                                        --sprite 1 with the cast member
                                        --assigned to gCurrentView.
  sprite(15).rect = sprite (theSprite).rect
                                        --When a location name is clicked,
                                        --the sprite number of the location
                                        --name is sent as a parameter (theSprite).
                                        --Move the highlight to the sprite that
                                        --was clicked.
  updateStage                           --Update the stage to show the new view
                                        --and the new highlight location.
end

on SetDirection theDirectionLetter, theSprite
							--When a direction letter is clicked, the
							--letter and the sprite number are sent
							--as parameters.
							put theDirectionLetter into gCurrentView.char[(gCurrentView).chars.count]
							--Replace the last character of gCurrentView
							--with the theDirectionLetter value that was
							--sent as a parameter. This generates a
							--new value for gCurrentView.
							sprite(1).memberNum = member (gCurrentView).number
							--Switch the cast member assigned to
							--sprite 1 with the cast member associated
							--with the new value of gCurrentView.
							sprite(16).rect = sprite (theSprite).rect
							--The sprite number of the direction letter
							--is sent as a parameter (theSprite).
							--Move the highlight to the letter that
							--was clicked.
							updateStage                           --Update the stage to show the new view
							--and the new highlight location.
							end
						

					  

Tip

This is a good place to use the continuation symbol (\ ). Press Alt+Enter (Windows) or Option+Return (Macintosh) to insert it wherever you feel the line is too long for you to read.

Now take a look at the new SetDirection handler that you added. As in the SetPlace handler, you define two arguments for the SetDirection handler: theDirectionLetter and theSprite. Recall the script you just looked at for cast member 30, the N button on the compass. When that script calls the SetDirection handler, it sends "n" for theDirectionLetter and 10 for theSprite. You will see how these are used in a moment.

The next line sets theDirectionLetter ("n" in the example) as the last character of gCurrentView. For example, if nubia.e is displayed and N is clicked on the compass, then e will be replaced by n in gCurrentView. This gives gCurrentView a new value. This line uses the put…into command, which is required when setting a character. Previously you used concatenation to combine text to create gCurrentView. In this case, you replaced the last letter of the existing global variable gCurrentView.

Next you set the the memberNum value of sprite 1 (the view shown on the stage) to the cast member number of gCurrentView, which now has a new cast member name.

In the next line, you move the highlighting rectangle to cover the letter on the compass just clicked by setting the coordinates of the rectangle to the coordinates of the sprite specified by theSprite, the second parameter that was sent when the direction letter was clicked.

Finally, you update the stage to show changes.

4.
Close the Script window.

5.
Play the movie. Click all the direction letters on the compass except S. Also click location names.

You can now navigate to any image in the collection by clicking the location names and direction letters, except if you want to see the southern views. You'll create the handler for the southern view now.

6.
In the Cast window, select the N, cast member 30. Then click the Script button.


Figure .


7.
Copy the script. Then close the window.

You're going to use this script as the basis for the script for the S cast member.

8.
In the Cast window, select the S. Then click the Script button.

9.
In the Script window, paste over any text already there (Edit > Paste). Then make the change shown here in bold:

on mouseUp
  SetDirection( "s", 12)
end

Be sure to use a lowercase s or the handler won't function properly. This handler will call the SetDirection handler you just created in the movie script. The arguments for the SetDirection handler are theDirectionLetter and theSprite. The mouseUp handler here plugs "s" into theDirectionLetter and 12 (the sprite number of the S) into theSprite.

10.
Rewind and play the movie. Click all the locations and all the direction letters.

They all work!


Figure .


11.
Save your work.

Good work! The data storage and retrieval procedures you just developed can be used for a variety of information types of all sizes.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint