Command Reference - Action Examples
|
Actions used: |
List Box Object - Get Item Data List Box Object - Get Item Text List Box Object - Get Property |
In this example, we'll use a "File - Search" action to search for text files on the user's desktop. Then, we'll use a simple WHILE loop to get the name of each file, one at a time, and add the name to a List Box Object.
Here's what the action list on our Add button's "On Mouse Click" event looks like:

Here's what the action list on our Remove button's "On Mouse Click" event looks like:

Here's what the action list on our List Box Object's "On Selection Changed" event looks like:

Since we've commented these actions pretty well, we won't describe all three action lists in detail. Instead, we'll focus on the actions that deal with storing items with data in the list box object.
First, on our Add button's "On Mouse Click" event, we use a "List Box Object - Add" action to add a name and phone number to the list box. The name is added as item text, which is the part that shows up in the list box. The phone number is added as item data, which is an optional part of every list box item that is only stored internally, and not displayed in the list box at all.
Each item in a list box is actually just a single string, that can be divided into two parts (item text, and item data) by a pair of colons (::), like so:
item text::item data
Note that only the part up to the :: is displayed in the list box.
We want to store the name and phone number in the list box, with the name appearing in the list, and the phone number being stored as item data. This is really easy. We already retrieved the name and phone number from their respective Edit Field Objects, and stored them in a variable called %Name% and a variable called %Phone%, so we simply add an item consisting of this string:
%Name%::%Phone%
...to the List Box Object.

Note that the item text and item data are always separated by ::, regardless of what you put in the Delimiter field. The Delimiter field is for when you want to add multiple items at once. For example, we could add three name::phone number items to the list box at once (in a single string), like so:
Russ T. Nail::(204) 555-5123;;B.B. Gunn::(502) 555-9922;;Peter Owt::(920) 555-4321
Now let's explain the actions in our List Box Object's "On Selection Changed" event. When the user selects an item in the list box, we want the name and phone number for that item to appear in the corresponding edit fields on our page.
First, we use a "List Box Object - Get Item Text" action to get the name from the currently selected item, and store it in a variable called %Name%. Remember that the name was stored as the item text. (This is the "visible" part of the item string on the left side of the "::").

Next we want to get the phone number, which was stored as the item data. (This is the "hidden" part of the item string on the right side of the "::"). In order to retrieve the item data, we need to determine the index of the selected item. (This is because the "List Box Object - Get Item Data" action can only retrieve the item data for an item at a given position or "index" in the list.)
So, we use a "List Box Object - Get Selected" action to get the index of the selected item, and store it in a variable called %index%.

Then, we use a "List Box Object - Get Item Data" action to get the item data from the item at that index, and store it in a variable called %Phone%.

Then, we use a "Edit Field Object - Set Text" action to copy the text from our %Name% variable into the "EF - Name" Edit Field Object...

...and another "Edit Field Object - Set Text" action to copy the text from our %Phone% variable into the "EF - Phone" Edit Field Object.

Here's a link to the finished example, as an AutoPlay Media Studio 4.0 page that you can import into your own project: