Planning For Development
Never try to launch a rocket without fuel.
I’ve been testing (with a mild level of success) whether there are easier ways to handle external data in Flash. Each person’s situation is different and completely dependent on the resources they have available to them but what if such a method existed?
The best solutions for handling data in Flash all come down to the amount of work put in at the planning stages of a project. For instance, when I began my Flash IMS (Image Management System), one of the first classes I wrote was a file handling class. In the early stages, I was positively sure that I would be using this class repeatedly to get all of my image data into Flash. Turns out…I was WAY wrong.
After sitting down and building out a rough draft of the database structure (in mySQL), I realized that most of the functions which originally encompassed the SD_FileHandler class weren’t necessary at all and after clean-up I was left with one solitary function. The functions only responsibility is to crawl through a directory looking for a specific image type (the default is jpg) and is only used by the admins to administer the site. I ended up writing an entire second class that pulled content per the area of the site it was needed and even this class doesn’t use the SD_FileHandler class or its solitar function “fileFilesOfType”.
function findFilesOfType($dir, $type=’.jpg’){
$jpgs = array();
$dirHand = opendir(SD_BASE_PATH . SD_CUSTOMER_URL . $dir . “/” . SD_PCIMAGES_DIR);
while($file = readdir($dirHand)){
if(substr(strtolower($file), -4) == $type)
{
$jpgs[] = $file;
}
}
sort($jpgs);
return $jpgs;
}
Because my final approach to handling the data was a mySQL database, there really aren’t any files which require php file handling at this level so my original class is really quite defunct. In the final System, Flash simply calls a PHP file which in turn calls the IMS classes and loads the data specific to the situation. Ironic if you ask me.
The point is this, whenever you start a project, always make the extra effort during the planning stages. It will prevent more headaches than it will cause, hours of debugging and in the end, provides a clean, simple approach to handling the task at hand.