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

Lesson 11. Assembling the Complete Proje... > Setting Up the Initialization Functi...

Setting Up the Initialization Function and the Reset Button

After a crash course in functions, you are now ready to apply this knowledge to the Dante movie. In this task, you will enclose all of the actions needed to specify the initial state of the movie in a custom function. Then you will call this function from two different places, setting the movie to its initial state.

In lower.fla, select frame 1 of the actions layer, open the Actions panel, and just above the chiron._x= line, enter a new line, as follows: function initMovie() {. Indent each of the lines that set the position of a monster instance, and add a closing } after the whole block.

In this step, you are creating the function and adding all of the monster instances' positioning to it. The initial state of both the dynamic text fields (the info box and dragtext) is not yet included; you'll add that in a moment.

Using cut and paste, move the line dragtext.htmlText=dragtext_startText; and the line info.htmlText=info_startText; so they are inside the new function.

When you are finished, only the original stop() action and the lines that set the two global variables should remain outside the function. The reason that these three lines of code remain outside of the function is that they never need to be reset, since nothing in the movie can change them. All of the lines of code inside the function reset something that could be changed by the user.

Beneath the closing } of the function, insert a new line of code as follows:


This line is necessary, because again, the function doesn't do anything unless it is called. This line calls the function, so as soon as the movie loads and the function is loaded, it is immediately called, thus initializing the movie.

Select the Reset button, open the Actions panel, and enter the following script:

							on (release) {

This script calls the function when the user clicks the Reset button, restoring the movie to its original state.

Test the movie. Drag the monsters to their posts, click a circle label, such as Fraud, and drag the scrollbar down to the bottom. Then click the Reset button.

The Reset button restores the movie to its original state—almost. Did you notice that the scrollbar remained down at the bottom, even after the Reset button was clicked? That's not going to work!

You've fixed this problem before, by using the setScrollPosition() action on the scrollbar component instance (infobar). That line needs to be added to the initialization function, for the Reset button to reset the initial state of the info box.

Select frame 1 of the actions layer, and in the Actions panel, enter the following script anywhere inside the initMovie() function block:


By using the initMovie() function, you kill two birds with one stone. That is, correcting the script this one time in the function effectively corrects the mistake in the two places that call the function.

Save your file.



Not a subscriber?

Start A Free Trial

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