The Card Script In Detail

This lesson will describe the Card script in detail and may be of interest if you are trying to learn revTalk. If you would just like to get your Video Player working as quickly as possible the you can skip this lesson and come back to it later. In this case you should have copied and pasted the entire Card Script that was provided in the previous lesson.

Create The uiPopulateVideoList Command

Create The uiPopulateVideoList Command

In revTalk you can write commands that perform certain operations. We are going to write a command the populates the List Field with available videos. The definition for a command starts with the word command (1), followed by the name of the command (2). To finish the definition of the command you write end (3) followed by the name of the command (4).

What Will The Command Do?

What Will The Command Do?

Before writing the actual revTalk that populates the List Field I've added some comments that describe what I want to do. This can be helpful as the comments tell the story of what needs to happen. I can then go back and write the revTalk that actually performs the required actions.

The Completed Command

The Completed Command

Here is what the command looks like when it is finished. The command calls a function call GetVideoFiles() (1) that returns all of the available video files, each one separated by the return character. We will look at what a function is in the next step.

The command then assigns the list of video files to the text property of the Video Menu List Field (2). Assigning the text property of the List Field changes what you see in your Stack window.

Copy & Paste Into Card Script

command uiPopulateVideoList

## Get list of video files in Video folder

put GetVideoFiles() into theFiles

## Assign the list of files to the list field (our menu)

set the text of field "Video Menu" to theFiles

end uiPopulateVideoList

The GetVideoFiles Function

The GetVideoFiles Function

In the uiPopulateVideoList command we called a function that returns a list of video files. As of right now there is no function named GetVideoFiles that has been defined. Let's do that now.

You define a function the same way that you do a command except that you use the word function rather than command. Notice how you can just add the definition of the GetVideoFiles function after the definition of the uiPopulateVideoList command. You can add any number of function and command definitions to a script.

The purpose of GetVideoFiles is to return a return delimited list of all video files in the Videos folder that you created earlier. In order to do this we will need to get the path to the Videos folder on disk and then get a list of all the files in the folder. GetVideoFiles makes use of two other functions that help do this: GetPathToFolder and GetFilesInFolder. We will define this two folders next.

Copy & Paste Into Card Script

function GetVideoFiles

## Get the path to the "Video" folder on disk

put GetPathToFolder("Videos") into theFolder

## Get list of files in the folder

put GetFilesInFolder(theFolder) into theFiles

## Return list of files

return theFiles

end GetVideoFiles

The GetPathToFolder Function

When working with video the video files are stored separately from the application that we are creating. In this case the video files are stored in the Videos folder. When you share your application with others it is important that your application is able to find the video files on the computer it is running on. GetPathToFolder helps do this. The purpose of the function is to take the name of a folder, in this case "Videos", and return the full file path to that folder.

You can read the comments in the function if you want to learn what it is doing but for now you can just copy and paste it into your Card script and now worry about the details.

Copy & Paste Into Card Script

function GetPathToFolder pFolderName

## Retrieving paths to folders that are relative to the stack can be tricky.

## Determine the location of this stack on disk

put the filename of this stack into theFolder

## Folder paths use "/" to separate each folder in the path

## By setting the itemDelimiter to slash we can refer to

## individual sections of the path by the 'item' token in revTalk.

set the itemDelimiter to slash

## When you build a standalone version of this stack on OS X the stack

## file will be located in side of an application bundle. These next few

## lines strip the application bundle portion of the path off.

if the platform is "MacOS" then

if theFolder contains ".app/Contents/MacOS" then

## Delete the last three items of the path that are specific

## to the application bundle

delete item -3 to -1 of theFolder

end if

end if

## Replace the last item in theFolder with the 'pFolderName' parameter

put pFolderName into the last item of theFolder

## Return the complete path

return theFolder

end GetPathToFolder

The GetFilesInFolder Function

The GetFilesInFolder Function

The GetFilesInFolder function is a handy way of retrieving a return delimited list of files located in a particular folder on a computer. The parameter you pass in, pFolder (1), is the path to the folder whose files you want to retrieve. The function then uses the defaultFolder and the files (2) to get the list of files.

Copy & Paste Into Card Script

function GetFilesInFolder pFolder

## This function uses the default folder to get a list of files

## Store the original default folder so we can return to it later

put the defaultfolder into theOrigDefaultFolder

## Change the default folder to the folder passed into the function (pFolder)

set the defaultfolder to pFolder

## 'the files' always returns the files in the 'default folder'

put the files into theFiles

## Restore the original 'default folder' setting

set the defaultfolder to theOrigDefaultFolder

## Filter out invisible files (files that start with a "." in their name) from 'theFiles' variable

filter theFiles without ".*"

## Return the list of files to the caller of the function

return theFiles

end GetFilesInFolder

Compile the Card Script

Compile the Card Script

Now that you have modified the revTalk in your Card script you need to compile the script. Whenever an object script has been modified the dot in the object tab will turn yellow (1). Click the Compile button (2) to compile the script. The dot will then turn green if the script compiled correctly or the Script Editor will alert you if there is something in your script that needs to be fixed, e.g. you typed something incorrectly.

Also note that after you compile a script the list of commands and functions that you have defined in your script appear in the left column (3). This helps you quickly navigate to a particular handler (a handler is either a command or a function) in your script.

Test the uiPopulateVideoList Command

Test the uiPopulateVideoList Command

We have now added all of the commands and functions to the card script that are necessary for uiPopulateVideoList to work. Let's test it out. Use the Window menu to select the Video Library Stack window and bring it to the front.

Open The Message Box

Open The Message Box

Now we are going to use the Message Box to test the uiPopulateVideoFiles command. The Message Box is a tool that allows you to execute revTalk statements. Click on the Message Box button in the toolbar.

The message box will appear and should look something like this. Make sure that single-line messages mode is active.

Call uiPopulateVideoList

Call uiPopulateVideoList

Type uiPopulateVideoList in top field and press the Return key (1). Because the Video Library stack (2) is the target of any commands executed in the Message Box the uiPopulateVideoList command you defined in your card script will be executed.

Done

Done

After pressing the Return key the List Field should populate with the videos in your Videos folder.

2 Comments

Jon

This code:
command uiLoadSelectedVideo
## 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 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.
92=> 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
end uiLoadSelectedVideo

produces this error:
card id 1002: execution error at line 92 (Chunk: no such object) near "My Video", char 19

Hanson Schmidt-Cornelius

Hi Jon,

your application is missing the player "My Video".
Similar to when you created the field "Video Menu", just drag the "QuickTime Player" on to your card and give it the name "My Video"

Kind Regards,

Hanson

Add your comment

E-Mail me when someone replies to this comment