Set transform to middle via JSFL

November 27th, 2012 by Slav

I just wrote a quick JSFL script for the Flash IDE that I though I’d share..

Example of situation where this could be useful.  You just imported a bunch of images from photoshop via PSD importer. All of those would have a bitmap inside of them , that would be left top aligned to registration point, and so would be his parent.

However, you’d like to have some of those bitmaps center aligned as you want to do some nice scale in / rotation tweening like this for example :

TweenLite.from(my_mc, .4, {scaleX:2, scaleY:2, rotation:90, alpha:0, ease:Back.easeOut});

Instead doing all of this manualy:

  1. double clicking on the clip to go inside it
  2. selecting a bitmap
  3. center align it
  4. making sure it’s on the whole pixel position (deleting .5 from x or y position)
  5. going out of edit mode
  6. selecting parent and moving it back by the half x and y width / height offset
  7. repeating this for all the elements you need to have center aligned!

you can simply right-click on this link and select “Save link as” and download it to your commands folder.

On win 7 this is : C:\Users\[YOUR PROFILE NAME]\AppData\Local\Adobe\Flash CS5\en_US\Configuration\Commands

Then in Flash IDE just select desired clips on your stage and select “CenterClipToMiddle” from the menu.

It will only work on one child in nested timeline of the MovieClips you select on a stage. I have automatic rounding of position as well both for parent and nested clip, so it will always be on a whole pixel value.

Any questions or suggestions for improvement just give me a shout in comments below.

Posted in AS3, flash, JSFL

2 Responses

  1. Pierre

    Why do you round the positions to whole numbers and re-apply the offset to the parent object? Are you exporting the assets to PNG Spritesheets or something like that?

  2. Slav

    This is done specifically for psd import to flash IDE, where you will have a single bitmap inside of the sprite on the stage.
    If your bitmap AND wrapping sprite aren’t on a pixel, you will get extra anti-aliasing as flash will try to compute and interpolate bitmaps..
    My script will make it dead easy to center the bitmaps INSIDE of these wrapping sprites, while preserving the positions of the wrappers.
    You would typically want to have them middle aligned for any transforms like scale or rotate that need to transform from the middle..