9 Grid Scaling with BitmapData (AS2 Version)

January 11th, 2008 by Slav

This is a 9 grid scale implementation class for BitmapData.

 

It was inspired by the  the post on Bytearray blog , well this is basicaly its “slightly” different AS2 implementation.  It’s aimed to be used mainly with the imported bitmap data (e.g. buttons from the photoshop PSD file). You need to have a library linkage name and “Export for ActionScript” checked on the bitmap.  

The simplest way to use it, is to create an instance of a new ScaleBitmap and pass the 3 mandatory arguments :

  • newWidth – this is new / resized width of the bitmap from the library
  • newHeight – this is new / resized height of the bitmap from the library
  • linkageID – the export linkage name Identifier of the Bitmap library asset.

var myScaleBitmap = new ScaleBitmap(newWidth,newHeight,linkageID);

with this 3 arguments, the class will auto create a 9 grid scale rectangle for you, by dividing the width and height in thirds.

However you can pass a 9 grid rect as a 4th parameter..

9 Grid Rectangle is a inner rectangle (see illustration) that will slice the BitmapData into 9 parts.

When you resize the bitmap the corner parts never scale, only move, only middle, left, top, right, and bottom scale.

 BitmapData9gridIllu

to create a new ScaleBitmap with your custom 9grid rect use the syntax :

var myScaleBitmap = new ScaleBitmap(newWidth,newHeight,linkageID,rect9grid);

Other parameters that you can send to the constructor include : “alpha”, “color”, “smoothing” are documented inside of the class.

ScaleBitmapDemo zip

Posted in AS2, flash

10 Responses

  1. teamflash

    Thanks! – this is going to make my life with designers much easier…now menu buttons in 6 different sizes wont end in tears!

  2. LL

    This is really nice but it would be nice to have as a Flash 8 file since scale9 was introduced in Flash 8.

    The file seems to be CS3, can you repost a sample as F8? Please!

    Thanks!

  3. LL

    Regarding the CS3 file saved back to version 8….. may I saw WOW you have some wonderful posts here on your blog!

    Unfortuantly the files seem to be CS3 even though they are AS2, can you re-save them to Flash 8 please? I would really like to utilize and learn from your samples and classes, some very wonderful stuff, thank you for sharing!!

    Some really wonderful stuff, I am glad I found your blog!

    Thank you again. I would really appreciate if you could save to Flash 8.

    Again WOW great stuff, I will be a regular reader!

  4. LL

    I am just posting again as my previous posts did not show up, or maybe you have not had time get to them yet. Sorry for bugging!

    Firstly, again I wanted to thank you again as mentioned in my two previous posts. (hopefully you received them)

    I was hoping that you could re-save your samples that are AS2 as Flash 8, you have some very informative items here at your blog and I wish to learn from your examples.

    I would be very thankful if you would take the time to do so, I am sure alot of people would be gracious also.

    Thank you.

  5. Slav

    Sorry for the delay in replay, normaly I get the mail after the comments are being submited, must be some problem with the comments spam filter.

    I have uploaded the flash 8 version for this now.

  6. MuhelyTitkok

    Wow! Finally I’ve found the AS2 version. This one is freakin cool man!

    Beautiful work! Thanks very much.

  7. Rob’s geeky discoveries Blog » Script Generate on Stage Filters with JSFL

    [...] Could be very useful so thought I’d share. Was originally looking for 9-slice scaling stuff and found this excellent resource page with a nice way of scaling PNG’s to 9 slice for buttons/UI elements. The AS2 version is at http://durej.com/?p=59 [...]

  8. Bagera

    Great resources on this site.
    I found a lot I might use but what are the licencing terms for work you publish here.

    best regards

  9. Slav

    This is my way of giving back to flash community so all downloable assets/classes/zip files etc from this site are free to use for both commercial and non-comercial projects.

    The only prohibited use is if someone would try to sell or otherwise profit directly from FLAs/classes/jsfl sripts. If they are being use within the projects then it’s fine of course.

  10. Vince

    Thank you for your site. I have found here much useful information…

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.