Share this Page URL
Help

Chapter 16. Interfacing with External Da... > The LocalConnection Object - Pg. 315

Interfacing with External Data 315 thisOne rather than this["clip_"+i] in the following lines). Then I make a generic object (thisData) onto which I'm about to set three named property values (x, y, and c). The cli- pLocs array will become an array full of generic objects (one for each clip), and those objects will each have an x, y, and c property. Lines 20­22 assign values for those three properties, based on the values for the current clip's _x and _y properties plus the homemade variable c (which contains a Color object instance). Then line 23 stuffs the generic object onto the end of the array (using the push() method). Finally, the current value for my_so is written to disk in line 25. Now that we know how data was saved, we can look through the restoration code (lines 4­12). Realize lines 4­12 will be executed in the first keyframe, provided that the condition in line 3 is true --that is, the my_so's data has a count value. So, if we get to line 4, we know they're returning and we need to restore the variables and display. Line 4 shows the only variable we really need from the local SharedObject file: count. That is, we need to make sure that count starts where they left off. The rest involves creating instances, putting them in the right location, and coloring them all according to values in the clipLocs array (which is a property of the data property of the my_so instance). Line 6 creates a new clip, and line 7 stores a local variable to save typing in the next few lines. Line 8 makes a new instance of the Color object into a variable c (of the current clip). Line 9 sets RGB (based on the c value found in the current position of the clipLocs array). Notice that the portion my_so.data.clipLocs[i-1] appears in several places. This simply returns the value in a particular slot of the clipLocs array (namely, the i-1 slot because i goes from 1 to count and arrays count starting at 0). The value in that slot of the clipLocs is itself a generic object (with three named properties). Looking at line 10 and 11 is somewhat intimidating unless you break it down or read it backwards: We're setting this one's _x and _y equal to the x property of the generic object in the current slot of the myLocs array (which itself is a property of the data property of the my_so instance). Believe it or not, I think it was easier to write than it is to read. If