Movie Control
Top  Previous  Next


Description:
Demonstrates how to control timelines playing in Sprites and how Sprites can control the main movie timeline.

Aim
This tutorial introduces various uses of the gotoAndPlay() actions.


1. Open the file "helloworld.swi" ... save the file as "mymoviecontrol.swi".

2. On the 'Outline' panel, use the Insert menu and insert a new Scene into the movie - it should be titled Scene_2 by default.

3. Click on "Scene_1" in the 'Outline' panel and insert a Text object into the movie by using the text tool. Change the default text on the text panel to read "Hello World" and make sure that it is a Static text object. Set the text justification to Center panels-object-text-center by using the Justification options drop-down menu panels-text-justifyoptions on the text panel, and make sure the text is using the Vector character options panels-text-vector as shown below:

scripttute11_1

4. Make sure the text object is highlighted in the 'Outline' panel, then use the Modify menu and select Grouping | Group as Sprite (or you can also Right-Click on the text object in the Outline panel and follow the same procedure.

scripttute11_2

5. Name the sprite "mymessage" on the Sprite panel. Make sure to select (highlight) the sprite in the 'Outline' panel and click on the (+) icon to open it - this will allow you to edit the timeline inside the sprite.

scripttute11_3

5. Open the 'Script' panel. Press the 'Add Script' button and select Events | Frame | onFrame(...) from the menu - leave the frame number set to "1". Next, press the 'Add Script' button again and select Movie Control | stop() from the menu.


6. Press the 'Add Script' button again and add another onFrame() event and change the frame number to "5". Use the 'Add Script' button again and select Frame | setLabel() from the menu and set the label name as "start". The script panel should appear as show below:

scripttute11_4

7. In the 'Timeline' panel, Right-Click at Frame 5 on the row for the "Hello World" text object and select Zoom | Zoom In from the menu. Next, Right-Click at Frame 20 on the same row and select Zoom | Zoom Out from the menu. The 'Timeline' panel should be shown as below:

scripttute11_5

8. Right-Click on Frame 30 for the "mymessage" sprite row (directly under the ruler) and select Movie Control | gotoAndPlay | nextSceneAndPlay() from the script menu.

scripttute11_6

9. The 'Script' panel should be show as below:

scripttute11_7

10. Click on "Scene_1" in the 'Outline' panel and click on the AutoShape tool. Draw a Beveled Button shape on the Layout panel below your text object.

scripttute11_8

11. Insert a Static text object using the text "Click Me" and position it over top of the beveled button shape. Select both the text object and the beveled button shape (hold down the CTRL key while clicking on each object in the 'Outline' panel) then use the Modify menu and select Grouping | Group as Group from the menu.

scripttute11_8b

12. With the Group selected in the 'Outline' panel, open the 'Script' panel and press the 'Add Script' button. Select Events | Button | on(press) from the menu.

scripttute11_9

13. Press the 'Add Script' button again and select Movie Control | gotoAndPlay | gotoAndPlay(LABEL) from the menu. Use the 'Target' drop-down menu and select the "mymessage" sprite from the list then select the "start" label. The resulting script should be shown as below:

scripttute11_10

14. Select "Scene_1" on the 'Outline' panel and add a stop() action on Frame 2 (using the methods described above).

scripttute11_11

15. Select "Scene_2" on the 'Outline' panel and insert a Static Text object. Change the text to read "Thank You".

16. In the 'Timeline' panel, Right-Click at Frame 1 on the row for the "Thank You" text object and select Fade | Fade In from the menu. The 'Timeline' panel should be shown as below:

scripttute11_12

17. Right-Click at Frame 11 on the row for "Scene_2" in the 'Timeline' panel and select Movie Control | stop() from the menu.

scripttute11_13

18. Make sure you are in the 'Layout' panel then press the playmovie 'Play Movie' button from the Control Toolbar. When the movie starts playing, press the "Click Me" button. You should see the text "Hello World" zoom in/out then the text "Thank You" will fade in.

19. Press the 'Stop' movie button and save the .swi file.


Analysis
When the "Click Me" button is pressed, it sends a command to the Sprite "mymessage" telling it to go to the label "start". At the label the text animation begins, and when the animation stops (at Frame 30) there is an action inside the Sprite telling the main timeline to go to the next Scene and play. By using the gotoAndPlay() action - you can set different Targets to send commands from the main timeline to a Sprite and from the Sprite back to the main timeline.