Posts Tagged ‘ACTIONSCRIPT3’

Sunday, June 14th, 2009

Rozengain or Dennis Ippel of AKQA updated probably one of the tools I use the most for flash 3d and that is the blender to as3 exporter.  This simplifies loading in the meshes you have and lessens the bulk of the COLLADA format.  COLLADA is great but flash is still client side and fairly memory intensive for 3d so loading in models directly to as3 is nice if flash is your presentation tool.

AS3 Blender exporter has been updated to allow multiple object export. Also in April is was updated to export quads and modifiers.

One concern you might have is statically binding the code within a main swf fileon compile and resulting file size compared to loading in the DAE dynamically.  But you can just load these in as you would external DAE COLLADA files as compiled swfs and since it is just code it is very compact.   This adds some duplication of code (such as tweening libraries or the 3d engine source as needed) but allows a more horizontal loading or lazy loading of meshes when needed.

This is just another option to get 3D models into the flash 3d engine of your choice in addition to COLLADA, some MD2 support and limited ASE support.

This is an awesome project that keeps getting better, thanks Rozengain.

Friday, May 22nd, 2009

Flash 10 will be ready for mainstream hopefully by the end of this year, or early ’10 when the penetration numbers will be up in or around the 90% range via zeh fernando based on previous trajectories.  

With that, Flash 10 has many great new things such as the Vector structure that allows a collection of a certain type, which results in a faster collection because of the known type.  So anywhere where Arrays are used, that is a possible candidate for a performance increase within some code because you are asking the virtual machine to do less work on each loop (not having to dynamically find out the type).

ByteArray (Thibault Imbert) has demonstrated that for the JPEG encoding in corelib it is up to 2.5 times faster using Vectors than Arrays.  Your mileage may vary heavily but it is almost a guaranteed speed boost due to less work.  This obviously has great possibilities for speeding up code that uses lots of arrays.  

Due to the performance boost the Vector does have some constraints in the typical give and take of coder flexibility with compiler and virtual machine overhead.  Vectors are more explicit and strongly typed which is why they are fast, but this is also limiting.

In addition to the data type restriction, the Vector class has other restrictions that distinguish it from the Array class:

  • A Vector is a dense array. Unlike an Array, which may have values in indices 0 and 7 even if there are no values in positions 1 through 6, a Vector must have a value (or null) in each index.
  • A Vector can optionally be fixed-length, meaning the number of elements it contains can’t change.
  • Access to a Vector’s elements is bounds-checked. You can never read a value from an index greater than the final element (length - 1). You can never set a value with an index more than one beyond the current final index (in other words, you can only set a value at an existing index or at index [length]).

 [ Vector docs  ]

ByteArray not only used Vectors heavily but did other optimizations that are always good to do, even though optimization is evil when you are working with precious client side resources ensuring an optimized base starting point can be a good thing.

So what did I do ?

  • I used bitwise operators as much as possible.
  • I replaced all Arrays with fixed length Vectors.
  • I used pre-incrementation rather than post-incrementation (thanks Joa for this one ;)).
  • I casted to int all my Vector indices access.
  • Other minor stuff you always do to optimize your code 

Other sources as well for even more optimization or shall I say efficient AS3:

Friday, March 13th, 2009

Polygonal labs, maker of some of the best demos, information and tools for AS3 since inception updated the killer AS3 Data Structures for Game Developers and ported it to haXe.

Of course along the way making many improvements and showing great information on how and why the haXe version is faster which mainly boils down to a more strict virtual machine but flexible still with generics.

haXe is fast because it is a very highly optimized virtual machine language with compiler (and could be called a virtual machine to target other VMs similar to LLVM with the ability to target the Neko VM, AVM2 or Javascript, it is more than just a language) by Nicolas Cannasse that may one day overtake directly coding for the AVM2 or maybe we will even see haXe have more influence on flash soon for performance gains.  Some of the Alchemy LLVM virtual machine work is similar in nature to what haXe does and helps the language become an abstraction and translates into highly optimized code from very powerful and productive language syntax.

Anyways, I ramble, be sure to check out Data Structures for Game Developers by Polygonal Labs now ported for haXe as hx3ds if you are doing any sort of work in AS3 or haXe for AS3 it will be worth your while and provide a very common and useful data structures capabilities into your production that is highly optimized from one of the best AS3 developers.

As the name suggests, hx3ds is a port of as3ds for haXe and is now available at hx3ds only supports the flash player 10 target, as it makes extensive use of the Vector class. If you need data structures that compile across all platforms, take a look at colhx instead.

Here’s a list of new features:

  • orders of magnitude faster
  • collections now support clone() and shuffle() operations
  • object pooling framework
  • revised graph, tree and linked list classes
  • memory manager for the virtual memory API (more on this soon)

The Structures Included

Multi-Dimensional Arrays

The library contains a two-dimensional and three-dimensional array. They are both implemented by a single linear array rather than nested arrays. This is the fastest method in flash to simulate multi-dimensional arrays and outperforms the nested array method because multiple array lookups are slower compared to one lookup combined with a simple arithmetic expression (which you can also often precompute in the outer loop). The most obvious application would be a tilemap in 2d or a layered tilemap in 3d.


This is also called a FIFO structure (First In – First Out). The queue comes in two variations, which have the same methods, but differ in their implementations: There is the arrayed queue, which obviously uses an array internally, and the linked queue, which is build upon a linked list. They are both very similar, except that the arrayed version has a fixed size and is faster.
A common application would be a command queue – imagine you have a unit in a strategy game and apply many commands which the unit should follow. All commands are enqueued and afterwards dequeued and processed in order.


Also commonly know as a FILO structure (First In – Last Out). Like the queue, this comes in two flavors: arrayed and linked. A stack is often not used directly, but a very important concept in programming. Please note, that a queue and a stack are not real structures, because they just define how data is accessed rather then stored.


A node-based structure. Every tree starts from a single node, called the root node. The root node can contain any number of child nodes, and every child node can again contain children. A tree node with no children is called a leaf node. In fact if you draw the nodes of a tree it looking like a real tree with branches. The AS3 display architecture is also a tree structure, so you could use this to manage your display objects and update them by traversing through the tree. Also, this is useful for decision trees, BVHs, storing a plot line or storing data recursively by applying the composite pattern.

Binary Tree

This is just a specialized kind of tree where each node is only allowed to have up to two children, called the left and right node. Binary trees are very often used for parsing input data, for example arithmetic expressions or when building a scripting system.

Binary Search Tree (BST) and Hash Table

Both structures store data that can be retrieved quickly by using a key. The method however differers greatly: The BST uses a recursive approach to split up large amounts of data into smaller sets. A hash table stores sparse key-based data using a hash-key in a small amount of space.

Linked Lists

A linked list is similar to an array. The main difference is that in an array, each cell contains just the data and is accessed by an index. A linked list consists of several node objects, which in addition to storing the data, manage a reference to the next node (singly linked) or to the next and previous node (doubly linked) in the list. Think of it as a more natural approach to work with sequential data.
Other benefits are that you can insert and remove data quickly by just calling the appropriate method on the node itself – you don’t have to manage array indexes. Also in AS3 object access is faster than array access, so it competes very well in terms of performance when iterating over the list.

Heap and Priority Queue

A Heap is a special kind of binary tree in which every node is bigger than its child nodes. Whatever you throw into a heap, it’s automatically sorted so the item with the ‘most significant’ value (depending on the comparison function) is always the front item. A priority queue is build upon the heap structure, and can manage prioritized data – which can be used in limitless ways.


A graph is a loose node-based structure. Nodes are connected with arcs, and every node can point to any other node. They can also point to each other creating a bi-directional connection. It is essential for path finding, AI, soft-body dynamics with mass-springs systems and a lot more.

Bit Vector

A bit vector is some kind of array in which you can store boolean values (true/false – 1/0) as close as possible without wasting memory. I currently can’t think of a reasonable application, because usually you should have enough memory – but it’s nice to have because it shows basic bit masking operations.

Thursday, February 5th, 2009

Recently two compact tweening engines have been released. Grant Skinner’s GTweeny and laborat’s ByteTween. This adds to the two that focus on micro-tween kit sizes in TweenLite and TweensyZero

Basically these engines look to be micro and provide pretty nice features while being so small. Micro tweening engines like GTweeny (3k), ByteTween (1.7k), TweenLite (2.7k), TweensyZero (2.9k) and Tweener (9k) have varying levels of support of features (Tweener being the most loaded with color and filter support without other kits just init, also TweenLite with a nice configurator to include only what you need).  Micro kits have benefits when used for banners, animated assets (where you have many assets and the per asset savings is worthwhile) and other places you just want really small output.

Light Transition ByteTween


This kit has a c# version as well as a small as3 bytetween version.

The ByteTween static class eats only 1.7K of compiled clip! With this size it supports:

  • Creation of tweens of any numeric property (not color/uint properties).
  • Pause,Unpause,Cancel operations based on the tween target and property.
  • Overlap system that cancel tweens of same property in order to avoid erroneous behavior
  • Alpha tween with negative alpha support (negative alpha sets the MovieClip visibility to false)
  • ’scale’ tween of both ’scaleX’ and ’scaleY’ properties.
  • OnComplete callback with any number of parameters
  • Easy interface for creating new tweens!

Download (c# version)



(2.7k) base

  • SPEED – I’m not aware of any popular tweening engine with a similar feature set that’s as fast as TweenLite. See the speed comparisons yourself.
  • Feature set – In addition to tweening ANY numeric property of ANY object, TweenLite can tween filters, hex colors, volume, tint, saturation, contrast, frames, and even do bezier tweening, plus LOTS more. TweenMax extends TweenLite and adds even more capabilities like pause/resume, rounding, event listeners, timeScale, and more. Overwrite management is an important consideration for a tweening engine as well which is another area where the GreenSock tweening platform shines. You have options for AUTO overwriting or you can manually define how each tween will handle overlapping tweens of the same object.
  • Expandability – With its new plugin architecture, you can activate as many (or as few) features as your project requires. Or write your own plugin if you need a feature that’s unavailable. Minimize bloat, and maximize performance.
  • Management featuresTweenGroup makes it surprisingly simple to create complex sequences and groups of TweenLite/Max tweens that you can pause(), resume(), restart(), or reverse(). You can even tween a TweenGroup’s “progress” property to fastforward or rewind the entire group/sequence.
  • Ease of use – Designers and Developers alike rave about how intuitive the GreenSock tweening platform is.
  • Updates – Frequent updates and feature additions make the GreenSock tweening platform reliable and robust.
  • AS2 and AS3 – Most other engines are only developed for AS2 or AS3 but not both.

Download TweenLite


(2.9k) base

Here are some simple steps to help you get started with creating your first animations with TweensyZero. TweensyZero is a light weight version of Tweensy most core features found in Tweensy are available to TweensyZero. Documentation for TweensyZero can be found under the folder ‘documentation/zero’ or online

Download TweensyZero



gTweeny is gTween‘s lightweight younger sibling. It strips a lot of the secondary features of GTween (proxy, timing modes, etc) in favour of smaller file size. It is currently under 3kb…

Download gTweeny

Here is a list of all open AS3 “Micro” Tweening engines < 5k

Here is a list of all open AS3 Tweening engines and base kits

The decision on which to use can be affected be features you want, how it feels (many use the same object syntax so it is dynamic), what performance do they have (all are orders of magnitude faster than the built in tween (flash) or transitions (mx/flex)), which size is ok, author/community support needed (some are more active than others adding features or simplifying and tweaking performance methodically), and many other factors.  There are definitely plenty to choose from.

Speed Tests for many Tween Engines

For more on each features see their sites or these previous lists on tweening engines:

Monday, February 2nd, 2009

Don’t know how I missed this but just this last month a new site has launched called wonderfl that allows quick as3 compilation side by side that is encouraged by community and similar to a demo scene.

This could be great for generating new ideas much like machima and demo scenes have done in the past.  This stype of stuff goes down with the flash community anyways but being able to do it on a site and fork and evolve scripts and game it is a great idea.

Effects with filters, bitmaps, pixel manipulation, pixel bender and papervision would benefit greatly from the type of innovation that could happen here quickly in small doses. See what you can throw down, maybe some fireworks.

Thursday, December 4th, 2008

When you do lots of any language you build up libraries over time that are time savers that are repetitive and tedious if you do not consoildate into a library.  Taking a look at the CASALib, an as3 library of common functions for flash that was released I have many of the same things in my libraries but CASALib just has lots of extras that go a bit deeper than some libraries, is very clean and is organized pretty well.

One cool thing about it is the IDestroyable interface and the CasaMovieClip, CasaSprite, CasaTextField , etcthat all have a destroy() method that cleans up all events, removed instances and even removes it from the parent display object. Gets me thinking why this isn’t just part of DisplayObject in the first place.

From the release:

Here are a few of our favorite things in CASA Lib AS3:

  • Standardized external load API
  • Easily remove listeners with IRemovableEventDispatcher
  • destroy methods make garbage collection easy
  • Large group of utility classes for common manipulations

We will be elaborating further the power of CASA Lib in future blog posts.

As with any new release there will be bugs that emerge, but with your help we promise to release updates often to keep CASA Lib as stable as possible.

1.0.0 Downloads & Documentation




Saturday, November 8th, 2008

The YouTube Chromeless Player works with AS3/ActionScript 3.

The demo shows great examples of the player with just the window canvas (chromeless) from both javascript and inside of flash.

The project is hosted on Google Code [youtubechromelesswrapper-as3]

Looks like they maybe had a contribution for this, so do it where you can.

This is something we’ve been wanting to provide for a while, and the YouTube API team greatly appreciates the work of developer Matthew Richmond of The Chopping Block for making it happen. Thanks Matthew!



Public Methods

player.loadVideoById(id:String, startSeconds:Number = 0):void
Loads and plays video based on specified id.
player.cueNewVideo(id:String, startSeconds:Number = 0):void
Loads but does not automatically play video based on specified id.
Clears currently cued/loaded video.
player.setSize(w:Number, h:Number):void
Sets the size of YouTubePlayer instance.
Plays the currently cued/loaded video.
Pauses the currently cued/loaded video.
Stops the currently cued/loaded video.
Seeks to specified time within the currently cued/loaded video.
Returns the current state of the currently cued/loaded video.
Returns the value of current bytes loaded of the currently cued/loaded video.
Returns the value of total bytes loaded of the currently cued/loaded video.
Returns the current position in time of the currently cued/loaded video.
Returns the current duration of the currently cued/loaded video.
Returns the start bytes of the currently cued/loaded video.
Sets the volume of the currently cued/loaded video.
Returns the current volume of the currently cued/loaded video.
Stores the current volume and changes the volume of the currently cued/loaded video to 0.
Returns the volume of the currently cued/loaded video to the last stored value when muted.
Returns the current YouTube embed code of the currently cued/loaded video.
Returns the current YouTube video url of the currently cued/loaded video.


Fired once the Chromeless Player has successfully completed loading and is ready to accept operations calls.
Fired whenever the player’s state changes. The YouTubeLoader class translates the JavaScript API numbers to their related string values, the YouTubeLoaderEvent class stores the current event in a variable called state. Possible values are unstarted, ended, playing, paused, buffering, video cued. When the SWF is first loaded, it will broadcast an unstarted event. When the video is cued and ready to play, it will broadcast a video cued event.
Fired when an error in the player occurs. There are two error codes possible: 100 is broadcasted when the video requested is not found. This occurs when a video has been removed (for any reason), or it has been marked as private. 101 is broadcasted when the video requested does not allow playback in the embedded players.
Sunday, September 28th, 2008

Flash 10 security changes requiring user interaction are pretty breaking but they are for good reason.  Still though, the user could be inundated with prompts much like UAC on Vista. But, it is necessary otherwise security holes can be troublesome with the flash player and the “sandbox” of the web.  Much like Java signing, Active-X acceptance, and thus local file access, these actions need some user approval, it is that liability thing.

But what is a bit lost in this is some of the new support specifically for game development and app development.

Support for things like RTMFP which is bringing UDP support to flash.  UDP and reliable UDP (ordered) is really needed when it comes to larger scale networking applications and support for p2p apps.  Games for instance, that are large like MMOs and highly interactive real-time engines, need UDP to be able to scale.  So this is pretty useful, yet it currently looks like it is tied to Flash Media Server.  It appears Adobe is staying ahead of SmartFox, Red5 and OpenFMS with stuff like this.

Another great move in the way of security updates for Flash 10 for games is the allowing input from keyboard keys while in full screen mode. All these games and apps look pretty sweet in full screen until you try to use them.  There is only support for “Tab, the Spacebar, and the (up, down, left, right) arrow keys” but that is a start.  Enough keys for a casual game.  But still most keys could safely be used it must be a multi-platform support thing.

Limited full-screen keyboard input

Currently Flash Player does not allow keyboard input when displaying content in full-screen mode. Flash Player 10 beta will change this, allowing for a limited number of keys to be usable in full-screen mode. These include Tab, the Spacebar, and the (up, down, left, right) arrow keys.

Flash 10 is getting local save and load, this is great for any type of online editor, game or application. The ability to work on a file immediately without the server round trip initially is great.  I hope this is extended much further to local save and load with very high limits, there has been some confusion on the file size limitations here. Ideally this would be extended much further if the product direction is right. Typically making apps or games with more than 5-25MB of content quickly become non-economical in bandwidth such as gaming assets due to browser cache size limitations (defaults IE=50MB, Safari 5-25MB, FF3=50MB), I wish there was a better way to allow local saving for long periods of time.  Almost installing apps via flash with extended cache, talk about killer app feature. Downloading 10 MB of gaming assets that you know will be there for the month rather than the day.

Paste events can read the clipboard.  Using the clipboard is another great useful tool in applications and online editors.

Data can be read from the Clipboard inside a paste event handler

In Flash Player 9, the system Clipboard could not be read at any time. With Flash Player 10 beta, the new ActionScript 3.0 method Clipboard.generalClipboard.getData() may be used to read the contents of the system Clipboard, but only when it is called from within an event handler processing a event.

So yes, the security user interaction changes do break current features but it also takes this platform a bit more into secure applications and game features from security changes, hopefully these features are extended much further but they are on the right track.

Thursday, April 24th, 2008

This is older, from january, somehow I missed it but… nitoyon has created an AS3 port of jQuery. jQuery is my favorite javascript tool besides javascript itself. Mootools, prototype, and others like mochikit are all great but jQuery was the first to do lambda chain decorating and others followed suit.

But having this power in as3 is a great thing! $ selectors, common access methods to properties, methods, etc. All good stuff. Again this shows the fun in as3 or ES4 based languages like Actionscript because people are porting all sorts of libraries to it. If this performs I may just start using it daily TODAY!

For instance setting the stage align for use in full screen:

$(stage).attr({scaleMode: "noScale", align: "TL"});

That is too fun… The only thing not cool about this is all the spam at nitoyon‘s blog : )

How about a functional Tweener call:

function animate(f:Boolean):void {
				// Select 'RoundRect' elements using CSS selector
				$("RoundRect:" + (f ? "odd" : "even"))
						rotation: 90,
						scaleX: 0.5,
						scaleY: 0.5,
						time: 0.6,
						delay: 0.3,
						transition: "easeOutCubic"
						scaleX: 1,
						scaleY: 1,
						time: 0.5,
						delay: 0.9,
						transition: "easeOutElastic",
						onComplete: function():void {
							// restore the rotation and call again.
							this.rotation = 0;

Stuff to see and try

Friday, March 28th, 2008

I have been one upped by mr. doob! I did a little nascar like RC pro am like prototype in march ’07 when the pv3d kit showed up on my screen and I was hooked like most suceptible flashers who have longed for 3d in flash! Only my version is like Nintendo64 and his is like xbox360 with updated effects and physics kits and some doob magic. All these are based off of, of course the original race car driver in Papervision and its creator Carlos Ulloa (Adobe should be paying this man).

To the feature! This is a sweet game by mr. doob, called burn and brag for Nascar.

Now I don’t’ particularly like Nascar all that much but who doesn’t like to peel out to some fiddlin’? I mainly do Nascar stuff because it is highly marketable and like the only answer most ad agencies have for getting the southern us markets it seems, that and c-o-u-n-t-r-y mu-si-c (must be said at a slower rate).

But I digress, this is a perfect mix of advertisment, game play, fun and experience. It is fast, simple, and playable. Exactly the simplicity and smoothness needed of gameplay and playback.  Great ad work but it also gives something fun to do and best of all it is built in AS3 flash with a plethora of libraries from the flash as3 community.

The game platform is emerging fantastically in the AS3 market. mrdoob used these kits to build this:

It would be cool to see a post on how he did the replays with tweener – I imagine just a series of points collected with car state (current position state) and then just play them back with a call back or time delay. You’d have to capture alot for smooth playback without laggy movements.  I am working on multiplayer games with this same issue for a current project.

Game on! The question is when will this be SOTD or SOTM at