Flash Bitmap 9-Slice Scaling (AS3)
I actually wrote this last week for a project I’m working on, so imagine my surprise when I see Grant Skinner’s post on 9-slice scaling bitmaps in Flash.
His method uses a JSFL script to pre-slice bitmaps into separate MovieClips, which is great, because it’s otherwise a complete pain. Mine works on a different principle, and is for runtime use.
My Slice9Bitmap script uses the pixel data from the Bitmap passed into the constructor, then transfers the appropriate pixel data to each slice, ensuring perfect stretching. Attempting to stretch the entire bitmap beforehand is…messy (also, why you can’t do 9-slice scaling with pure CSS2/Javascript (outside of canvas)).
Currently, there is no boundary checking (other than for negative values), so it’s up to you to implement this. Alternatively, you could wait until I add more features (which could be anywhere from weeks to months, honestly).
View Slice9Bitmap demo
Download Slice9Bitmap.as
Also, if you’re not a hardcore Actionscript guy, Grant’s method is quite ideal.


