First Public Flex Module

I’ve placed my first public Flex module into my portfolio as a feedreader for this website. It’s a very simple module using no ActionScript to speak of and components are being styled directly from within their properties. It’s a good first step with Flex and something that is useful for me, so I view it as a success. The next step for my learning experience will probably be the integration of ActionScript within an app and either styling the components globally, or re-skinning them alltogether.

Coming from the Flash/ActionScript side of things, it’s been difficult getting a grasp on Flex and how everything works on that side. I’ve done a number of small experiments in the past few months but nothing useful till now. It’s beginning to come together for me though- I have the feeling that after the initial hurdle, things will explode for someone already familiar with ActionScript.

Feedreader

[feedreader source]

ActionScript 3.0 and the Flex SDK

In my free time (right!) over the past few months, I’ve been working on some basic ActionScript 3.0 projects to familiarize myself with the new version. I’ve been using FlashDevelop linked into the Flex SDK to write and compile my code. While I have no gripes with Flex Builder 2, I find it amazing that anyone can just download the Flex SDK for free and start producing Flash with pure ActionScript. I’ve lately been very focused on keeping my code clean and self-contained. With AS2, I’ve always needed to tie everything to an FLA in the Flash IDE, even if working primarily with external classes in FlashDevelop or SEPY. Having a pure AS3 environment is huge. One of my favorite new features is the ability to set document properties through your package definition.

1
2
3
4
5
package {
import flash.display.Sprite;
[SWF(width="400", height="350", backgroundColor="#000000", frameRate="31")]
public class SomeClass extends Sprite {}
}

I haven’t used AS3 for any real world projects yet, but with so many benefits over AS2 already realized from simple exercises, I know the day is fast approaching. I may begin a series of posts on the benefits of using AS3 over AS2 as I encounter these things in my work.

Drawing a BitmapData Object from a Masked Source

I recently stumbled upon a really nice trick while using the BitmapData object. The problem occurs when attempting to use the draw() method on a MovieClip instance source that had a mask applied via setMask(). Either nothing would be drawn, or the content would be drawn incorrectly. I’ve found that setting the cacheAsBitmap property to ‘true’ for both the source content and the mask itself will get around this issue.

1
2
3
leftContent.setMask(leftMask);
leftContent.cacheAsBitmap = true;
leftMask.cacheAsBitmap = true;

Forcing XML Refresh in ActionScript 2.0

I’ve been working with Flash since version 4 but only came across this trick a few weeks ago. Normally, when using the XML object in ActionScript to load data into your application, if the XML file has been cached, Flash will not reload updated XML data until the cache is cleared or expires. For many applications I’ve worked on, this has been a small issue as data can be updated many times during the day. To force Flash to always retrieve a new version of the XML, you must append a unique identifier to the URL in the load method. For instance, using getTimer(), you can say:

1
2
3
4
var myXML:XML;
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("http://somewebsite.com/data.xml?"+getTimer();