Category: Quick Tips

Resizing with RatioUtil

Written by Aaron Clinger on January 28th, 2009

With the increasing frequency of full browser and full screen Flash sites, many require dynamic content scaling. RatioUtil makes it easy to scale items while maintaining their aspect ratio.

PHP date in ActionScript

Written by Aaron Clinger on December 30th, 2008

When authoring CASA Lib we are often inspired by many other programming languages, frameworks and libraries. One of my favorite utilities in PHP is the date function. It is a great method for quickly formatting dates.

CASA Lib for AS2 and AS3 contain a DateUtil class. This class contains a formatDate method that acts almost identical to PHP’s date. The only change is that you use ^ to escape letters instead of \.

An example:

// Traces something like: "Tuesday the 30th of December 2008 10:24:13 AM"
trace(DateUtil.formatDate(new Date(), "l ^t^h^e dS ^of F Y h:i:s A"));

See DateUtil’s documentation for more information and options:

Get Access to the Stage Wherever You Need It

Written by Mike Creighton on December 21st, 2008

In ActionScript 2, it was possible to access the stage from anywhere, through the static Stage class. With ActionScript 3, we lost that ability, and only display objects were permitted access—and only once they had been added to the stage.

To help you get access wherever you need it, CASA Lib for AS3 has a utility class called StageReference in the org.casalib.util package. It’s a static class that lets you keep track of the stage (or multiple stages if you’re developing an AIR app with multiple windows). Here’s how we recommend using it.

In the constructor of your main document class, just call this line of code:

StageReference.setStage(this.stage);

Now, throughout your entire site or application, you can get access to the stage reference from anywhere by using this line of code:

StageReference.getStage();

Take a look at the class’s documentation to see what else the StageReference class can do. Some classes (like CASA Lib’s Key class) require the use of the StageReference class to function properly.

Feeds
Latest Posts