I heart Colin Moock

July 16th, 2008 by Steven Sacks

January 18, 2008: Colin Moock writes an article saying that AS3 is easy to learn and everyone from noob to master should learn it.

The community agrees (except me).

July 15, 2008: Colin Moock writes an article saying that AS3 is hard to learn and Adobe should make it easier.

The community agrees (me too!).

Oh to be Colin Moock. It must be nice to do a 180 and get the full support of the community both times. You only got my support once though, buddy. Welcome back, we've missed you. :)

Posted in Flash having 2 comments »

Parsing XHTML with E4X in AS3

July 2nd, 2008 by Steven Sacks

Gaia has an SEO feature that parses copy from the XHTML page and loads it into Flash. In AS3, it uses E4X. There are a few important things to know when parsing in XHTML using E4X.

First, you need to turn off ignoreWhitespace and prettyPrinting. The reason for doing this will be explained below.

XML.ignoreWhitespace = false;
XML.prettyPrinting = false;

Next, you need to set the default xml namespace to the xhtml namespace. This is one of the trickier parts for those unfamiliar with namespaces. If you don't do this, you won't be able to parse the XHTML.

default xml namespace = new Namespace("http://www.w3.org/1999/xhtml");

Then, you wrap the loaded html into an XML object. In this example, event.target.data is from the Event.COMPLETE of a URLLoader.

var html:XML = XML(event.target.data);

Now comes the fun part. Since valid XHTML is technically XML, E4X is able to parse through it exactly the same. In Gaia, I'm searching the XHTML page for a <div> with an id of "copy" to extract all the <p> tags out of it. Using E4X's descendant syntax, it's easy!

var copyTags:XMLList = html..div.(hasOwnProperty("@id") && @id == "copy")..p;

The above line of code searches all the div tags of the html file html..div for one that has an attribute called id hasOwnProperty("@id") and whose id attribute has a value of copy @id == "copy". Once it finds it, it returns an XMLList of all the <p> tags inside that div by using the descendant syntax ..p.

Now here's the tricky part. E4X was not specifically meant to parse XHTML, particularly node values with other tags inside them, such as paragraph tags. Inside <p> tags, XHTML often has other tags like <font>, <strong> and <em>. E4X sees these tags as child nodes, not part of the node value of the <p> tag. In order to get around this, you have to iterate through the children of the <p> tag and concatenate them manually.

For instance, if your <p> tag looked like this:

<p>This is <strong>bold</strong> text.</p>

The children(), represented as an Array, would be:

["This is", "<strong>", "bold", "</strong>", " text."];

Here's the code to parse and concatenate the node value of the entire <p> tag.

// get the first p node
var copyTag:XML = copyTags[0];
var str:String = "";
var len:int = copyTag.children().length();
for (var i:int = 0; i < len; i++)
{
        // concatenate each child
        str += copyTag.children()[i].toXMLString();
}

Unfortunately, E4X is going to inject the namespace into any tags inside the <p> tag, including the <strong> tag, resulting in your output looking like this:

"This is <strong namespace="http://www.w3.org/1999/xhtml">bold</strong> text."

This shouldn't have any bad effect if you assign it as htmlText to a TextField in Flash, but if you want to clean up the namespace, unfortunately, you can't use removeNamespace(), it just doesn't work. You instead need to use some fancy RegEx (graciously provided by Mike Keesey).

str = str.replace(/\s+xmlns(:[^=]+)?="[^"]*"/g, "");

This strips out the namespace="http://www.w3.org/1999/xhtml" from any and all tags inside the <p> tag.

Remember how we set prettyPrinting = false up above? The reason for this is that E4X automatically puts carriage returns between the tags inside the <p> tag, so you need to turn prettyPrinting off to get rid of them. If you didn't, the node value output would look like this:

This is
bold
text.

And, we also set ignoreWhitespace=false. If you don't have ignoreWhitespace set to false, then any spaces around tags inside the p tags will be removed and your node value output would look like this:

This isboldtext.

However, if you do everything correct, you end up with this as your node value:

This is bold text.

Of course, you could get around all of this by using the XMLNode class provided by Adobe for more AS1-style XML parsing. But that just wouldn't be as fun, would it?

Posted in Actionscript, E4X, Flash, Tips/Tricks having no comments »

Terrible Illustrator CS3 Bugs - Random moving and scaling

July 1st, 2008 by Steven Sacks

via Brad Merritt, Lead Game Designer @ Cartoon Network:

I am using Illustrator CS3 to create level layouts for an ingenious tool my Flash programmer wrote to parse my Illustrator layouts into proper level data for our game. This has made the workflow of game design to game programming smoother than ever. I simply place symbols from the library that are named in concert with our Flash elements.

However, an Illustrator problem is causing me unending headaches and lost work.

First, I struggled to find an easy way to make sure all objects snapped to whole pixel values (no decimals) and I could move objects by a single pixel. I finally settled in making 1px grid and turning on SNAP TO GRID.

Small Issue: Setting a grid size of 10px subdivided by 1px made my keyboard increments move 8px though my Keyboard Increments preferences is set to 1px. Setting grid to 1px fixed this.

Small Issue: Snap to grid works except when you drag a symbol from the library to the stage it does not snap to the grid. You have to move it again after you place it to make it snap to the grid.

Big Issue: Illustrator randomly moves and scales my objects on document close/open.

Step 1: This is my placed symbol with snap to grid.
Step 2: Save and close the file
Step 3: Open the same file and you get this:

This is happening to myself and my colleague working on a different machine on different documents on Illustrator 13.0 and 13.01 Windows XP SP2.

Posted in Adobe, Bugs, Illustrator, Workflow having no comments »

Gaia Site: Ribena by Swamp at Brahm, Leeds, UK

June 30th, 2008 by Steven Sacks

Swamp (Leeds, UK) utilized Gaia to rebuild their current website for GlaxoSmithKline's Ribena - from the ground up.

Senior Developer, Jozef Pierlejewski, writes about jumping in at the deep end…

"Faced with a 4-day initial build deadline, a load of assets from the designers and my own buggy transition engine, I went looking for a set of AS2 libraries that might help me speed up the development process and provide functionality that is common to most websites. Having been overwhelmed by the hardcore-MVC approach and highly technical documentation offered by some of the other frameworks I chanced upon Gaia.

Impressed by the possibilities demonstrated by the Rolling Rock website, I decided to investigate further. With praising testimonials from Jesse Warden, Aral Balkan and 2Advanced (well known names in the Flash community) I was now quite adamant that, despite the looming deadline, I should move my current prototype over to Gaia.

Here was a simply documented, well laid-out framework that even a beginner to real Object Oriented Programming could get to grips with. After a few late nights trawling Gaia support and simplifying my over-complicated code I had a rock-solid website in place complete with video transitions, which no amount of mid-navigation button-mashing could break. On top of that I had Deep Linking, Context Menu, and Browser History functionality automatically thrown in for good measure!

Gaia's methodology of stacked (rather than nested) pages took a while to adapt to, and there were a couple of minor isolated bugs to contend with, but Steven Sacks takes a very active role in the support forum and released a new update overnight to deal with any issue that I found.

Even though I have barely touched upon the surface of what Gaia can do, I can already see the time-savings that it would bring me on future projects like this and look forward to using it again."

Posted in Gaia having 1 comment »

Gaia Site: Design with Torlon by Liquid Interactive

June 30th, 2008 by Steven Sacks

designwithtorlon.com was developed for Quadrant Plastics by Liquid Interactive to promote the use of a particular product called Torlon. This site was developed using Gaia 2.1.8 AS3 with some customization the developer made for features Gaia did not yet support (which were added in later releases). It takes advantage of Gaia's integration with SWFObject and SWFAddress, preloading, asset management, and event system.

Jason Fistner, the lead developer at Liquid, had this to say about his experience with Gaia:

"Using the Gaia Flash Framework, we were able to focus on the site itself and not the complications involved in every Flash site build. Gaia abstracts out the difficult parts and provides a solid, no-bloat framework on which to build Flash sites. In addition, Gaia's sound logic and clean code also makes customization highly intuitive.

I typically refuse to depend on other people's code, but Gaia follows best practices throughout making it very difficult to do better. Even code formatting is done in the manner I believe to be the most conducive to digestion. It is almost as if I did it myself.

I am very comfortable using Gaia.

Steven's dedication, willingness to improve Gaia, and constant communication with Gaia users makes using the framework an easy decision."

Posted in Gaia having 1 comment »

Gaia 2.2.5 supports binding expressions

June 30th, 2008 by Steven Sacks

Gaia 2.2.5 has arrived and has some great new features. Among these features, binding expressions, landing pages, and framework optimizing top the list.

Gaia now supports binding expressions in the site.xml, similar to how Flex does it with MXML. This makes things like localization much easier. You can assign a binding expression to a FlashVar, to a public property in your Main class file, or a public property in any page class file. Anytime Gaia accesses the binding expression, it uses the current value, so you can change it at runtime. This allows you to do things like change the language on the fly. Rule!

Also, a new page attribute "landing" has been introduced. This has been requested quite a few times and now it's in. This allows you to set any page as a landing page regardless of whether it has children or not.

Framework optimizing is a fairly advanced feature which allows you to reduce the size of your main.swf file by up to 10k by not compiling unused Asset classes. Why compile classes you're not going to use? With a single button press, Gaia automatically comments out any unused code based on which assets are present in your site.xml. Add some new assets, optimize again, and Gaia will uncomment any new asset types that are present.

There are a few other little items, such as being able to use an id other than index for the index page, optimization of the SiteModel class, and some AS3 bug fixes.

You can read the full release notes and download Gaia here:
http://www.gaiaflashframework.com/forum/index.php/topic,581.msg2436.html

Posted in Gaia having 1 comment »

Gaia site wins Silver at Cannes Lions 2008

June 20th, 2008 by Steven Sacks

Silver Lion 2008

It's official. Gringo has taken Silver at the Cannes Lions awards for their agency website, Gringo's First Few Words…

André Brunetta used Gaia to build the Gringo site quickly and easily. As explained by Gringo:

"Gringo is an advertising agency lost in the far corners of the world. We only speak Portuguese but our friends from around the world love to teach us new words every time they pay us a visit! We are thankful for their help! Now we've gathered a very wide vocabulary and we feel ready to tackle Her Majesty Queen Elizabeth next."

Gringo's First Few Words...

Congratulations to Gringo and Andre Brunetta for yet another award winning site! Great work, guys! The site is really outstanding and definitely a break from the norm.

If you haven't seen the Gringo site yet, check it out, but you might want to put on headphones if you're at work or around children. :)

Posted in Awards, Gaia having no comments »

Gaia 2.2.0 - SWFObject 2 and more!

June 16th, 2008 by Steven Sacks

Gaia 2.2.0 is a major update and contains many awesome improvements and upgrades!

First off, SWFObject 2 + SWFAddress 2.1 are now fully supported. Updating older Gaia projects will automatically convert all your html pages, including your SEO Scaffolding ones, all while keeping any custom params and FlashVars you have in the old syntax. One click and your project is up-to-date with the latest SWF embedding technology. It doesn't get much easier than that!

Another cool new feature is queued on-demand asset loading. Gaia will now only open a maximum of two HTTP requests at a time, which means your Gaia site is more stable (people have reported AS3 becomes unstable when you have too many pending HTTP requests) and more responsive.

External pages now have a window attribute which enables you to target which window you want to open your link in right in the site.xml.

The panel now has Site XML and Class Path validation so you don't accidentally scaffold invalid class folder names (no spaces, no number at the start, alphanumeric), or invalid page ids. Additionally, the panel tells you exactly which nodes are invalid so you don't have to waste time trying to determine which ones they are.

Gaia now has AS3 Event Metadata for auto-completion when using Flex Builder 3.

Separate page templates for Actionscript and Timeline are now available for easy customization (and to solve a nasty JSFL bug with removeFrames).

Plus, some important bug fixes were made in both the framework and the panel.

And to top it all off, the latest version of the TweenMax family (v 1.17) is also included (released June 10th).

If you haven't tried Gaia yet, what are you waiting for?

http://www.gaiaflashframework.com/forum/index.php/topic,542.0.html

Posted in Gaia having 1 comment »

Gaia 2.1.9 is now available

June 11th, 2008 by Steven Sacks

Gaia 2.1.9 is here and contains a variety of improvements and updates, including a new flow called CrossFlow, and ApplicationDomain support for AS3. Gaia is now distributed under the MIT License.

You can download the latest version of Gaia and read the release notes here:
http://www.gaiaflashframework.com/forum/index.php/topic,534.msg2253.html

Posted in Gaia having no comments »

JSFL Rename Folder

May 26th, 2008 by Steven Sacks

JSFL does not have a method to rename a folder, which means you have to create a new folder with the new name, copy all the contents of the old folder into the new one, and then delete the old folder. It's a bit of a pain.

Here is the JSFL code to do this until Adobe sees fit to add a rename folder method. You can also use this to move a folder from one place to another.

function renameFolder(sourcePath, targetPath)
{
    FLfile.createFolder(targetPath);
    copyFolders(sourcePath, targetPath, FLfile.listFolder(sourcePath, "directories"));
    copyFiles(sourcePath, targetPath, FLfile.listFolder(sourcePath, "files"));
    FLfile.remove(sourcePath);
}
function copyFolders(sourcePath, targetPath, folderList)
{
    var i = folderList.length;
    while (i--)
    {
        FLfile.createFolder(targetPath + "/" + folderList[i]);
        copyFiles(sourcePath + "/" + folderList[i], targetPath + "/" + folderList[i], FLfile.listFolder(sourcePath + "/" + folderList[i], "files"));
        copyFolders(sourcePath + "/" + folderList[i], targetPath + "/" + folderList[i], FLfile.listFolder(sourcePath + "/" + folderList[i], "directories"));
    }
}
function copyFiles(sourcePath, targetPath, fileList)
{
    var i = fileList.length;
    while (i--)
    {
        FLfile.copy(sourcePath + "/" + fileList[i], targetPath + "/" + fileList[i]);
    }
}

Posted in JSFL, Tips/Tricks having 3 comments »

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.