You can now import the finished dialog into Director and start testing it out. Because you already know how to import graphics as well as set markers and create basic scripts, some of the interface for the trainer application has already been put together.
Open mytrainer_start.dir from the Lesson06 folder on the CD-ROM and take a good look at it.
When the movie is first opened, you'll see the intro graphic over a black background. In the Score, you'll see three sections created by setting markers: intro, main and exit. When the movie is played, the main screen fades in over the intro graphic and then sits at the pause on frame 40, within the main section. Notice in the main section of the Score that the sprites occupy down to channel 146! This because every day within the calendar display has three associated fields: the main one to display the data, one to display the day of the month, and one to indicate the type of exercise, if any, entered for that day.
In the Cast panel, three casts have been created: internal (which is always present), scripts, and cal_fields.
The internal cast contains the bitmaps and button images for the movie.
The scripts cast currently only contains a few very simple scripts, which you will be adding to as you create the application. Note that all the text fields on the calendar display have script member 4 attached, which sets the text property of each member to "" on beginSprite. This ensures that the calendar is cleared out before it is populated with data.
The cal_fields cast contains all of the text members used in the calendar display, as well as the fields that will display the weekly mileage totals.
Import the input_dialog SWF file from the project_two folder on your hard drive into the movie's internal cast.
The Flash asset appears and shows a small Flash icon within the cast member thumbnail. With the member selected, a new Flash tab within the Property inspector also becomes available, as shown here.
Although the defaults are fine, you could turn the Audio option off because there's no audio present in the Flash file. Other options let you control how the asset is played when animation is present, the speed at which it plays, and more. For now, you can leave the defaults as they are.
In the Score, click to select frame 30 of channel 148 and then drag the Flash input dialog from the internal cast and drop it on the Stage in about the position shown. Placing the dialog box in channel 148 insures it will appear over anything else on the Stage, since there are no sprites in any higher channels. Depending on how you created your dialog, you may have a border all around the black outline, or just at the corners. Either way, you'll want to set the sprite to use bg transparent ink.
Select the dialog box sprite, then select theSprite tab within the Property inspector. Set thesprite's ink type to Background Transparent to remove the border. Next, enter dialog for the sprite's name as shown. When you're done rewind and play the movie to test the dialog box.
Now for the fun part! As I mentioned previously, Director MX 2004 makes it much easier to use Flash assets in your work. To get the data from one of the fields, for instance, you need only poll the text property of the field's instance name within the sprite.
Pick the Running check box, and then enter John Muir into the Location field. Next, open the Message window by either pressing Ctrl/Command+M, choosing Window > Message, or by clicking its icon in the toolbar.
Within the Message window enter the following:
You should see the result:
-- "John Muir"
See how simple it is to retrieve the data from the location field within the Flash asset? Let's check to see if the Biking check box has been selected:
and the result:
Since you picked Running, the selected property for the Biking check box returns zero, or false. If you trace the selected property for the running instance, you will see that it returns true:
trace(sprite("dialog").running.selected) -- 1
Now, what about the Save and Close buttons? If you click one of them now nothing will happen, even though you placed the getURL() method on the buttons in Flash. What you need is a corresponding on getURL() handler in Director.
Stop the movie and select the scripts cast. Double-click to open the script named "Main Script" in member position 1 and then add the following handler to the empty script.
on getURL me, data trace(data) end
Now, whenever one of the buttons in the Flash asset calls the getURL() method, the Director handler will intercept the data being sent by Flash. Recall that in Flash all you are sending for the URL is either Save or Close, depending on which button is being pressed. This is what will be sent into the data variable within this handler.
Make sure the Message window is open and then play the movie and click the Save and Close buttons within the dialog box.
Whenever you press one of the buttons, you will see either "save" or "close" appear in the Message window, letting you know the code is working properly.
In the next lesson you'll build upon what you've created so far by adding the database functionality. But before finishing here, there's one small task you should take care of.
Because you only want the dialog box to appear when a day of the month is clicked onmeaning you want to enter data for that daythe dialog shouldn't be showing until that happens. There are two ways you could handle this: either set the sprite's visible property to false on beginSprite, or move the sprite off stage. We'll opt for the latter.
Stop the movie and select the scripts cast. Pick the input dialog sprite and then right-click and select Script from the contextual menu. Give the sprite the following behavior.
property original_locV on beginSprite me original_locV = sprite(me.spriteNum).locV sprite(me.spriteNum).locV = -2000 end on endSprite me sprite(me.spriteNum).locV = original_locV end
What happens here is that on beginSprite the original _locV property is set to the sprite's current locV. The locV property of a sprite is the sprite's vertical, or Y, position on the Stage. Next, the sprite's locV property is set to -2000. This effectively removes it from the Stage, as the very top of the Stage is at a locV of zero. The endSprite handler simply sets the sprite back to its original location when the movie is stopped or when the playhead leaves the sprite's span. Let's see how this works.
Give the behavior the name move offstage and then close the script window. Rewind and play the movie.
When the intro is complete, the calendar appears without the input dialog being visible, exactly as you wanted.
Stop the movie and save it as myTrainer within your project_two folder.
This lesson is now complete. In the next lesson you'll add additional Lingo as you implement the database for the project, as well as the calendar functions.