Ultrashock Tutorials > Flash 8 > XML Portfolio Viewer  
 
by Jim Armstrong, 2112 FX::Singularity
Download Source Files 
 
XML Portfolio Viewer
 
 Introduction and Code Requirements 
 Section 01: Layout XML  
 Section 02: Portfolio XML  
 Section 03: Architecture  
 Section 04: Preloading  
 Section 05: Error Handling  
 Section 06: pair & triple classes 
 Section 07: Observer-Observable Utility

 Section 08: Style Manager 
 Section 09: Layout Items  
 Section 10: Custom Layout Classes  
 Section 11: Glyph Class  
 Section 12: Multi-dimensional Thumbnailer  
 Section 13: Model 
 Section 14: View 
 Section 15: Controller 
 Section 16: Suggestions for Improvement 

pair and triple classes

Many of my past applications involved coordinate data. Some applications used cartesian coordinates while others used GIS data (lat,long). A few applications involved naturally paired numeric data that did not represent coordinates.

I tend to use specialized pair and triple classes to represent coordinate data. These classes were modeled after the C++ STL (Standard Template Library), although hardcoded for numeric data as Actionscript does not support compile-time templates.

Each class has methods for lexicographic comparison, vector norm computation, Euclidean- and great-circle distance computation. For GIS work, I prefer these custom classes to the new Flash 8 Point class. The lexicographic comparisons are a convenient way to determine if one location is southeast of another location, for example.

The pair and triple classes also contain methods to create new pair and triple instances as well as copy information from an existing pair or triple into a new pair or triple. There is a format() method to facilitate quick formatting of pair and triple data for printed output.

In some applications, numeric data is naturally paired, although the data has nothing to do with coordinates. The portfolio viewer is one such application. Properties such as horizontal buffer distance, vertical buffer distance, and outline buffer distance are collected as an ordered triple. Number of horizontal and vertical thumbnails in the thumbnailer are collected as an ordered pair.

This convention is carried over from previous implementations of the viewer. I personally think using the pair and triple classes is overkill for this application. The source code for these classes is included in the event you find them useful in other applications.

For more information on the pair and triple classes, including a complete test suite, visit www.2112fx.com/blog/pivot/entry.php?id=6 .

 
©2006 Ultrashock.com - All rights reserved