Loading Video Files When a User Selects a Video From the Menu
Now that the video menu is being populated we need to have the application load a video whenever the user selects a video in the menu. Let's look at how to do that.
Edit Card Script
Define The uiLoadSelectedVideo Handler
To start we need to define a command that will load the video file that is selected in the menu. uiLoadSelectedVideo will do just that. It gets the video file that is selected and creates a path to the video (1) that looks like this:
Note that the path to the video is a relative path rather than an absolute path. When you assign a relative path to the filename property of a Player object Revolution will try to locate the relative path using the folder that the stack file resides in as well as 'the default folder'. Since the Videos folder is alongside the stack file Revolution is able to find videos using the above relative URL.
Note for those using older versions of Revolution: Searching the folder that the stack file resides in in order to locate movies was added in Revolution 3.5. If you are using an older version of Revolution then you will need set the defaultFolder property to the folder the stack file is in.
Copy & Paste Into Card Script
## Get the name of the video selected in the video menu
put the selectedtext of field "Video Menu" into theVideoName
put "Videos/" & theVideoName into theVideoFile
## Set 'the filename' property of the player object to the relative video path
## Revolution will locate the video as long as the "Videos" folder is
## alongside the stack file or the application executable.
set the filename of player "My Video" to theVideoFile
## Reset the time of the Player object to 0
set the currenttime of player "My Video" to 0
Edit the List Field Script
Now we just have to tell Revolution that we want the uiLoadSelectedVideo command to be called whenever the user changes the selected menu item in the video menu. With the Edit tool activated (1) select the Video Menu List Field (2). Click on the Script button in the toolbar (3) to edit the object's script.
Whenever the user selects a line in a List Field Revolution sends a message to the field indicating that the selection has changed. This message is called selectionChanged. You can define what happens when this message is sent to the field by defining the on selectionChanged message in the field's script.
Remember that a Card script can have revTalk that affects all objects on a card. Since we have already defined the uiLoadSelectedVideo command in the Card Script we can call that command from the selectionChanged message of the List Field Script.
Copy & Paste Into List Field Script