Using ActionScript 3

With the help of:

I'm now working in Flash 9 Alpha and diving straight into AS 3.0 instead of continuing down the path of Flash 8 and AS 2.0. For a while, I was entertaining the idea of moving to Flex -- but there really is no need. For the moment, I'm building games and animation so Flash really fits the bill. Plus, my Flash files are considerably smaller than some early Flex tests that were at least 50 KB in size (as opposed to 1.4 KB in Flash). But I really wanted the power and efficiency of AS 3.0, so I then turned toward the idea of embedding Flash 8 movieclips in AS 3. This is certainly possible. And even desirable if you use the current version of FlashDevelop which can decompile Flash 8 and show you the embedded assets of a swf.

However, there are some limitations associated with importing assets from Flash 8. Code on the embedded resource timeline will not be executed. Presumably, you can't cast these objects to custom objects (though I was able to cast to a new type). If I turn my Sprite into MovieClip, I can control the timeline. I was able to do this with a 20 frame tween:

Actionscript:
  1. var tween:Sprite = new Tween();
  2. var tweenMC:MovieClip = MovieClip(tween);
  3. addChild(tweenMC);
  4. tweenMC.x = 100;
  5. tweenMC.y = 300;
  6. tweenMC.gotoAndStop(10);

I'm still scratching my head over when you would use a loader class versus not use it. Via a simple embed, my objects are compiled in and I don't need the external library to be present. By contrast, if I use a loader class, objects are loaded at runtime. In AS3 you can manipulate the imported object's DisplayObject properties. So perhaps you have more available to you... well, at least with a Flash 9 object (see comments here). But what's eminently clear is that, if you want to communicate between an AVM1 SWF and an AVM2 SWF, you need to use LocalConnection.

So... since I'm starting fresh with building animations, it seems as if it might just be better to build everything in Flash 9 and take the plunge to learning Object Oriented Flash programming.

Lab 2 instructions are to:

  • create an object on the stage
  • set variables that control its motion in horizontal and vertical directions
  • move it so it bounces off the edge when it moves past the edge of the stage on any side
  • create a second object that moves randomly about the stage

I'm already doing most of this in Lab 1. So the challenge is re-writing in Flash 9 ActionScript 3. I've got a little twist to this to turn it into a pong game.... coming up next post. I've found an excellent resource to help move this along a little faster... Keith Peters (the guy from BIT-101) Foundation ActionScript Animation book.
Foundation ActionScript Animation

2 comments ↓

#1 Keith Peters on 02.24.07 at 11:06 am

Glad you found the book and blog info helpful. As for your question on when to embed, when to load, generally you would embed smaller interface items that aren’t going to change - icons, maybe some skins. With larger items, it is often better to load them at run time, so they don’t slow down your application itself from loading. And of course anything that you might want to change often should be loaded so you don’t have to recompile each time.

#2 admin on 03.04.07 at 4:35 am

Thanks! This makes perfect sense.

Leave a Comment