Archive for the 'Flash' Category

15th May 2008

Flash Player 10 Available on Labs

Not much else to say on this one. There was a post on Flaskit board about this, so I thought I would put it here as well.

http://www.adobe.com/go/astro

Posted by Posted by Jeremy Wischusen under Filed under Flash Comments No Comments »

28th Apr 2008

Setting Up A Global Class Path In Flash

If you are just getting into using classes in Flash, chances are you are probably just creating your class (.as files) in the same directory as your FLA. This is simple, fast and works, but if I want to reuse a class from one Flash piece in another, I now have to copy over all of those class files into my new project directory. If I use that methodology, if I have to update something in one of my classes, I now have to update them in more than one location. This quickly turns into a maintenance nightmare and it turns out there is a simple solution.

Flash (as far back as mx 2007, not sure about older versions) will allow you to select a folder(s) where you can store classes that are used across multiple projects. This is commonly referred to as a class path. When you set up a class path and then do something like:


import com.mydomain.MyClass;
var myInstance:MyClass = new MyClass();

where MyClass is some custom class that you wrote, Flash will now look in your specified class path to see if it can find the corresponding class file (in this case MyClass.as). This means I am now free to use this class in any of my projects without having copy my class file into each project directory.

Please note that I am showing you how to set this for the program as a whole. You can also set this on a per document basis using the publishing settings

So how do we set this little piece of magic up?

  1. Got to the Edit menu and select Preferences.
  2. The following dialog box should appear:
    Flash Preferences
  3. Select ActionScript from the list on the left.
  4. Click the button entitled “ActionScript [version number] Settings” next to the Language label and the following dialog box should appear.
  5. Make sure to hit the + button resetting the entry that reads $(LocalData)/Classes will reset the default class path for Flash and Flash will no longer be able to find its built in classes. Clicking the + sign should make a blank line appear in the list.
  6. Click on the icon that looks like cross hair. This should bring up a file selection dialog box.
  7. Select the folder where you would like to store your classes.
  8. Keep clicking OK until all of the dialog boxes have closed.

Now you have your class path set up. This means that you can start storing you class files in this location. Please take note of the following:

  • Now that you have the class path set up, you can use import statements to bring in your classes just like you do with the standard Flash classes. For example import com.mydomain.MyClass; . Note a few things about the import statement.
    • The actual folder you selected is NOT included in the import statement (in my example C:\asclasses)
    • In import statements, dots = slashes. What I mean by this is that in our example, com.mydomain.MyClass is looking a file named MyClass.as in a folder mydomain that is a subfolder of com (i.e. /com/mydomain/MyClass.as). The beginning folder com in turn is actually a sub folder of the class path (i.e. C:\asclasses\com\mydomain\MyClass.as). Since we have setup C:\asclasses as a class path, Flash automatically looks in that location and we only have to specify the path using the dot syntax from that folder down. If you want to learn more about this dot syntax, do some research on the topic of packages in Flash.
    • As you may have noticed, you leave off the .as file extension.

Now that you have you class path set up, you can truly begin to start creating classes that are reusable across projects and only have to be maintained in one location.

Posted by Posted by Jeremy Wischusen under Filed under ActionScript 2, ActionScript 3, Flash, OOP Comments 2 Comments »

24th Apr 2008

DigitallyU Portfolio Software

So this may come off sounding like a bit of an advertisement, but this is one of the major projects I have worked on, so I thought I would mention it.

DigitallyU is the project where I got my start in Flash. We actually started creating it in Flash MX and the final product ended up being produced in Flash 8 (3 years of development in total). The major components of the system are XML, ActionScript, and MDM Script (the scripting language for ZINC, a program that allowed manipulation of the local file system long before Adobe AIR) .

The original idea started out as a method of allowing prospective college students to create multimedia  based portfolios for college admissions. This grew into the idea of portfolios for professionals and as people tested those versions for us they suggested that a generic version for building family media collections would be nice as well. Hence, we ended up with 3 versions; Scholarship, Professional and Scrapbook (the generic version).

The basic methodology of the program is that you select media files (images, sounds, videos and documents) from you local hard drive. For each portfolio the editor tracks the location of the selected files. When you are ready to publish your portfolio you choose from 40 or so templates designed to read exported output. Exporting (aka publishing) a portfolio assembles the selected files along with your selected template into a predefined web ready folder structure that can then be uploaded to the web, or put on some external media device.

The major difference between the version is how much we predefined what sections are in a portfolio. Scholarship includes predefined sections such as SAT scores, Professional mimics a resume and Scrapbook is a free for all. So we were not out simply to provide a generic portfolio tool, but also took into account the final audiences for the portfolios.

Currently, the software is in use at American University, Rutgers, University and the Worchester Preparatory School. We have been told that several students have taken their portfolios to admissions interviews and the response has been very good.

If you would like to play with it, trial version are available on the website http://www.digiallyu.com .

Posted by Posted by Jeremy Wischusen under Filed under Flash, General Comments No Comments »

15th Apr 2008

Using PHP’s DomDocument to Generate XML from an SQL Query

One of my side projects (well many of them now that I think of it) requires me to load data from a database on server into Flash. Back in the old days. and with simple data, I might have done something like:

echo ‘name=’.$name.’&email=’.$email;

… and so on and then load that string into a Flash LoadVars object, on in AS 3 a URLVariables via a URRequest.
This is ok for small simple data, but not so much for large amounts of data requiring a complicated string concatination.

Then one day it dawned on me that you can use the PHP DomDocument object to create a well formatted XML document and skip the whole string concatenation altogether. Furthermore, Flash makes loading external XML from a URL a very simple thing. Hence I could skip the whole LoadVars experience as well.

After doing this once or twice, I also realized that you could pretty much automate the whole process of generating the XML document inside the while loop for fetching the database rows. Essentially what I end up with is an XML document with tag names that match the column names of the table I am performing the query on with the node values matching the value for that row of the query.

Below is a sample of this and the output it produces with some of the more sensitive details removed:

PHP:

<?php
header (“content-type: text/xml”);

/*Create a DomDocument Object*/

$dom = new DomDocument(‘1.0’);
$dom->formatOutput = true;

/*Create a root element for the XML document*/

$root = $dom->createElement(‘stores’);

$dom->appendChild($root);
mysql_connect(‘localhost’,’username’,’password’) or die(‘Could not connect to db server’);
mysql_select_db(‘database_name’) or die(‘Could not select DB’);

$sql = ‘SELECT * FROM table_name’;

$call = mysql_query($sql);
while($row = mysql_fetch_assoc($call)){
/*For each row returned, create a node to represent that row*/

$store = $dom->createElement(‘store’);
$root->appendChild($store);

/*Loop through the returned row and create a node that matches the column name and use the value for the node’s value*/

foreach($row as $key=>$val){
$col = $dom->createElement($key,stripslashes($val));
$store->appendChild($col);
}
}
/*echo out the XML to the page*/

echo $dom->saveXML();
?>

Output (edited for sensitive data, but representative) :

<stores>
<store>
<companyName>Diamond Imports</companyName>
<companyDesc>
Diamond Imports is one of Australia’s largest diamond importers specializing in loose diamonds, certified diamonds, wholesale diamonds, excellent cut diamonds and ideal cut diamonds. Diamond Imports is 100% Australian owned and operated company based in Sydney.
</companyDesc>
<companyAddress>Bridge Street</companyAddress>
<suburb>Sydney</suburb>
<city>Sydney</city>
<state>NSW</state>
<AverageRatingGuarantee>5</AverageRatingGuarantee>
<AverageRatingSelection>5</AverageRatingSelection>
<AverageRatingHours>5</AverageRatingHours>
<AverageRatingService>5</AverageRatingService>
<AverageRatingAmbience>5</AverageRatingAmbience>
<AverageRatingCertification>5</AverageRatingCertification>
<AverageRatingKnowledge>5</AverageRatingKnowledge>
<AverageRatingImpression>5</AverageRatingImpression>
</store>
</stores>

To load this into flash or flex, all I do is point to the URL of the page that generates the XML:

var storeData:XML = new XML();

storeData.ignoreWhite = true;

storeData.load(“getStores.php”);

Posted by Posted by Jeremy Wischusen under Filed under Flash, PHP Comments 2 Comments »