Use Property: For Each with an Array of Values from a Script

This example shows another use of the "Property: For Each" repeat type. In this case, the value that the repeat keys off of is constructed by a script that defines a two-dimensional array (rather than a one-dimensional array as shown above).

The composition contains two clips: "Property setup Clip" and "Send Clip".

The script in the "Property setup" Clip and will set a property in the ""Send Clip"" that "Send Clip" then repeats based on. The "Send Clip" has "Property: For Each" set as above.

As was the case above, the setup for the "Second Clip" uses "Property: For Each". The repeat value comes from a custom property that is owned by the clip. Since this property is defined within the "Second Clip" in this example, the clip name doesn't have to be specified in the repeat value. The path {%% prop : clip : Channel Map %%} has been used to get the value of the current clip's custom property, which is Channel Map.

The script sets up a hard-coded array and then puts that value into the Channel Map property of the following clip (using currentClip.nextItem ).

The hard-coded two-dimensional array defined in this code is a list of cable TV channels. Each outer array contains an inner array with three values: channel abbreviation, channel description, and the channel number. This results in a 5x3 array (e.g. five entries, each with 3 values in it). The source code can be copied and pasted from here.

var channelMap = [ ["MTVJ", "MTV Jams", "134"], ["GREEN", "Planet Green TV", "201"], ["SHOXw", "Showtime Extreme", "582"], ["TVG", "TVG Horse Racing", "409"], ["HIS-I", "History International", "276"] ]; $context.currentClip.nextItem.propertyList.setPropertyValue("Channel Map", channelMap);

The "Property setup Clip" simply calls the script shown above.

The "Send Clip" sends one message and it uses the "for each" value that its containing clip is being called for. Any clip being repeated by "for each" has access to the value that it's being called for. In this case, the value it's being called for is in itself an array.

The first value on the right is getting the first element of the array, followed by the second and third for the "for each" value in use. To recap, the "Property setup Clip" will run a script that sets a property of the "Send Clip". The "Send Clip" will run once for each property value, which is in itself an array.

When this composition is played, the following Result Details are presented.

Note: The "Send Clip" has an entry without an index because its property was set before it began executing, and therefore, before it was known that it would repeat. Once it came time to execute the clip, it repeated five times, once each per "for each" value.

When the "Property setup Clip" ran it executed the script and was successful.

The Property value of the "Second Clip" got set by the script (only (Array) is shown as above).

Once the "Send Clip" was executed, the three values from the sub-array (the second dimension) within each value of the outer property array were inserted into each of the five runs of "Send Clip".

This example has demonstrated how a script is used to setup a complex grid of values. Another possible use for such a scripted array might be a grid of name and password pairs where the following clip is run for each name/value pair and also has access to both values in that pair.