« A Little Info on the Proxy in 1.5 | Main | Free Flex »

ActionScript Projects in Zorn

I've seen some people at the MAX conference get 2400 baud modem speeds while downloading the alpha version of Zorn from the new Macromedia Labs site. Remember that if you're here at the conference, many of us working on Flex have the software on a USB key. We're happy to let you copy the bits and start playing around.

At lunch today, talking with some people who haven't played with Flex, I realized that many people think that Flex is just for big applications. While we do want to do large enterprise apps well, we're certainly trying to help developers create smaller apps as well. And really, really small apps can be created if that's what you need, less than 1k, by just using ActionScript 3.

It's not that I want to promote building just in AS3 over Flex. The framework provides all the components that make life easier, plus I work on the Flex compiler. But for people who just want to play with AS3, need really tiny movies, or want to isolate a problem, I think it's very helpful to be able to write just ActionScript in a project.

I'm sure there's documentation on ActionScript projects, but here's a simple example to illustrate how to do this in Zorn. Create a "New Actionscript Project" and name it "ImageTest". Put a PNG called "myimage.png" in the directory of the project, which defaults to "C:\Documents and Settings\username\My Documents\Flex\ImageTest". Replace the code for ImageTest with this:

        import flash.display.MovieClip;
        import flash.display.DisplayObject;

        public class ImageTest extends MovieClip
            public var embedClass:Class;

            public function ImageTest()
                var embedObj:DisplayObject = new embedClass();
                embedObj.x = 100;
                embedObj.y = 100;

Then go to "Run > Run", set up a new configuration, and you'll see the image in a movie in the browser. With a png of 805 bytes, this creates a movie of 1,809 bytes for me. Looking at the AS3 and Embed documentation, you'll be able to see all sorts of interesting things you can do with the combination of Embed, DisplayObject, Bitmap, etc.

Comments (5)

mike chambers:


There is a captivate video on the labs wiki that shows how to set this up in Flex Builder:


mike chambers


Thanks for the link. I figured there was good documentation out there on this but didn't know we even had a video for it.

A few things to note about the class I quickly created above:
1. You don't need to use MovieClip, as I'm not using anything from that class. flash.display.Sprite will work just as well.
2. You don't need to set "x" and "y" for a created DisplayObject. I just set these to show one thing that can be done with the object.
3. You can type the embedObj as Sprite instead of DisplayObject. I didn't do this because this may change in a future release (to Bitmap).

erik seiz:

Thanks very much for posting an actionscript-only project example.

Big question: How do you link visual components (Button, List, etc) into a Flex Builder AS3-only project?

In mx2004, We would drag components onto the stage, and then erase them to bring them into the library so that we could use them inside our actionscript-only code. Using “import mx.controls.Button” in AS3 allows programs to compile, but they fail at run time because the component object is not found.

Hi Erik, you should just be able to import visual components and use them. I'm guessing that the Button does not work because it expects to be set up within the context of a Flex application. If you want to use the Flex components, you should start with an mxml page and use a Script block within that page.

One thing to note as a difference between AS2 and AS3 is that there is no separate symbol/component and class. That is, in AS2 there was two separate pieces that you had to bring in to a SWF for visual components- the symbol and the class. In AS3, there is only classes. Classes are everything in AS3 (and to anybody who knows the SWF format well, yes that does mean ExportAssets is gone). See Bitmap, Sound, Sprite, etc in asdoc for information on different types of assets that can be used.

erik seiz:

Thanks Brian. - You are correct, the answer was to embrace an mxml starting-point, and branch out from there. I am impressed with the clean symbiosis between mxml and AS3 classes. My original thinking was that mxml was just a crutch for non-developers, but I've come to realize that it's actually a complimentary extension for developers.