LoaderMax – Smart AS3 Loading
LoaderMax is a new AS3 loading system that does much more than just get swf, mp3, css, video, image, text, binary, and xml files into your Flash application. It eats files for dinner, burps, and then asks for 2nds. And 3rds. Yet it’s surprisingly thin. In fact, it can be half the size of most other loading systems even though it delivers a bunch of unique capabilities, some of which you probably never knew you needed but won’t want to live without. Here are a few of the noteworthy features:
- Integration of loaders inside subloaded swfs – with most other systems, if you subload a swf, the loader will only concern itself with the swf file’s bytes but what if that swf must subload other content like XML, images, and/or other swf files before it should be considered fully loaded? LoaderMax can elegantly handle the sub-subloads as deep as they go. You can link any loader and/or LoaderMax with a swf’s root (using the requireWithRoot vars property) so that when you subload it into another Flash application, the parent SWFLoader automatically factors the nested loaders into its overall loading progress! It won’t dispatch its COMPLETE event until they have finished as well.
- Automatic parsing of LoaderMax-related nodes inside XML – The XMLLoader class automatically looks for LoaderMax-related nodes like <LoaderMax>, <ImageLoader>, <SWFLoader>, <XMLLoader>, <VideoLoader>, <DataLoader>, <CSSLoader>, <MP3Loader>, etc. in XML files that it loads, and if any are found it will create the necessary instances and then begin loading the ones that had a load=”true” attribute, automatically integrating their progress into the XMLLoader’s overall progress and it won’t dispatch a COMPLETE event until the XML-driven loaders have finished as well. See XMLLoader’s ASDocs for details.
- Tight file size – Many other systems are 16-24k+ even if you’re just loading text, but LoaderMax can be as little as 7k (depending on which loader types you use).
- Define an alternateURL for any loader – If the original url fails to load, it will automatically switch to the alternateURL and try again.
- A common set of properties and methods among all loaders – All loader types (XMLLoader, SWFLoader, ImageLoader, MP3Loader, CSSLoader, VideoLoader, LoaderMax, etc.) share common properties like: content, name, status, loadTime, paused, bytesLoaded, bytesTotal, and progress as well as methods like: load(), pause(), resume(), prioritize(), unload(), cancel(), auditSize() and dispose() delivering a touch of polymorphism sweetness.
- Nest LoaderMax instances inside other LoaderMax instances as deeply as you want. – A LoaderMax instance is basically a queue of loaders which makes it simple to control them as a whole and get the overall progress, bytesLoaded, and/or bytesTotal. You can put a queue into another – group and nest them however you want. This makes complex queues simple. Need to know when the first 3 loaders have finished loading inside a 10-loader queue? Just put those 3 into their own LoaderMax that has an onComplete and nest that LoaderMax inside your main LoaderMax queue.
- Set a width/height for an ImageLoader, SWFLoader, or VideoLoader and when it loads, the image/swf/video will automatically scale to fit using any of the following scaleModes: “stretch”, “proportionalInside”, “proportionalOutside”, “widthOnly”, or “heightOnly”.
- Conveniences like auto smoothing of images, centering their registration point, noCache, setting initial x, y, scaleX, scaleY, rotation, alpha, and blendMode properties, optional autoPlay for mp3s, swfs, and videos, and more.
- Works around common Flash hassles/bugs – LoaderMax implements workarounds for things like garbage collection headaches with subloaded swfs, images, and NetStreams as well as other problems like the recently discovered issues with subloading swfs that use TLF.
- Find loaders and content by name or url – Every loader has a name property which you can use to uniquely identify it. Feed a name or URL to the static LoaderMax.getLoader() or LoaderMax.getContent() methods to quickly get the associated loader or content.
- A single loader can belong to multiple LoaderMax instances
- Accurate progress reporting – For maximum performance, set an estimatedBytes for each loader or allow LoaderMax’s auditSize feature to automatically preload just enough of each child loader’s content to determine its bytesTotal, making progress reporting on large queues very accurate.
- prioritize() a loader anytime – Kick an object to the top of all LoaderMax queues to which it belongs, immediately supplanting the top spot in each one.
- A robust event system – events bubble up through LoaderMax hierarchies and carry a consistent target for easy identification
- Set up multiple event listeners in one line – Add listeners like onComplete, onProgress, onError, etc. via the constructor like new LoaderMax({name:”mainQueue”, onComplete:completeHandler, onProgress:progressHandler, onError:errorHandler});
- maxConnections – Set the maximum number of simultaneous connections for each LoaderMax instance (default is 2). This can speed up overall loading times.
- pause()/resume() – no queue loading solution would be complete without the ability to pause()/resume() anytime.
- Flex friendly – Simply change the LoaderMax.contentDisplayClass to FlexContentDisplay and then ImageLoaders, SWFLoaders, and VideoLoaders will return content wrapped in a UIComponent.
AS3 Scale9 Bitmap
AS3 Scale9 Bitmap is class that lets you create scale9 sprites with bitmap data fill – originally this was not possible in Flash 9. The class creates a “fake” scale 9 sprite containing 9 shapes that scale according to user-defined scaling matrix. Extremely useful for quick user interface work (creating buttons, scalable UI elements etc.)
http://www.uza.lt/codex/as3-scale9-bitmap/
Bitmap Mosaic
From the site:
This class will allow you to create a pixellated copy of any display object.
It allows for varying pixel sizes and caching of rendered pixels so you don’t have to redraw them every time.
http://juliankussman.com/blog/2008/10/01/as3-bitmap-mosaic-class/.
MarchingAntsSelect
From the site:
This is a simple ActionScript 3 implementation of the class marching ants selection marquee you find in applications such as Photoshop.
The class is based off this ActionScript 2 example here; http://www.nocircleno.com/experiments/selection_ants_proof/index.html, but adds in many more methods and is entirely self contained. Drawing the bitmaps for the marquee internally in the class.
Features
Either Fixed or user drawn marquee
Draggable or static fixed marque
Programatically changeable marquee colours
Programatically changeable marquee line thickness
Does not rely on library assets for marquee
http://www.blog.noponies.com/archives/80
WindowBlur
Blurs a background (MovieClip or Sprite) behind a transparent window (MovieClip or Sprite). Based on Pixelfumes AS2 class.
From the site:
I was checking out a website yesterday when it suddenly reminded me of a Pixelfumes experiment I remembered seeing many moons ago. After finding it with a quick Google search, just for kicks, I decided to play around and update the idea to AS3.
http://blog.onebyonedesign.com/?p=81
AnimatedBitmap
From the site:
The AnimatedBitmap class provides functionality for Bitmap objects that are animated by using a series of still images. When creating a new AnimatedBitmap you provide a BitmapData object that contains an image that consists of the ’single-frame’ images for the animation.
http://labs.hexagonstar.com/animatedbitmapclass/
CollisionDetection
From the site:
The com.gskinner.sprites.CollisionDetection class is really simple to work with, there is a single static method called checkForCollision with four parameters:
checkForCollision(movieClip1,movieClip2,alphaTolerance);
movieClip1, movieClip2 – The MovieClip instances to check for collision.
alphaTolerance – a number from 0 to 255 that specifies the transparency tolerance when testing the collision. A higher number will increase the tolerance (ie. allow more transparent parts of the MovieClip to register collisions). Defaults to 255.
Returns a Rectangle object specifying the intersection of the two MovieClips in the _root coordinate space, or null if they do not intersect.
http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html
DistortImage for AS3
an updated version of the original DistortImage class for AS2, which allows you to programmatically distort images.
http://www.rubenswieringa.com/blog/distortimage
DistortImage
Distort Images programmatically in AS2.
http://sandy.media-box.net/blog/distordimage-the-way-to-distord-bitmaps-by-code.html
ImageLoader
From the site:
ImageLoader is a straightforward image loader. It simplifies the job of loading images by automatically creating a list of images being loaded, controlling its queue with priority features (by way of the LoadingQueue class), and by caching images locally using BitmapData instances. This means that when you try to load a new image, it actually loads the image, saves its BitmapData, and attaches the image to the container (with smooth turned on). Additional image loadings will simply be skipped and the cached bitmap is used instead. Simultaneous downloads also “understand†each other so if you’re loading the same image on two different containers at the same time, they will have the correct loading percent set and events fired.