views:

24

answers:

2

I'm using UILoader to load SWF files which I have no source for. These SWF files were created in AS2. They use masks. Width and height return unmasked values.

I'm trying to find the visible width and height of the clip so I can scale it properly.

For example I want a SWF to fit within a 50x50 space. The visible SWF is 65x65 (but I don't know this) and the unmasked size is 100x100. If I set the width and height of the loaded movieclip to 50x50, Flash scales the clip based on the unmasked portion, and I get a clip scaled much too small. Keep in mind I have no control of the SWF content, so I can not override width/height, or get mask size.

A: 

a couple of ideas:

  • Method 1- Decompile the AS2 swfs , then override the width & height properties to return the mask's width & height

  • Method 2- Create a new AS2 swf, that will try & retrieve the dimensions of the loaded swf's mask. Since I don't use AS2 , I'll just explain the logic. Test the mask property of your movie, if it's not null, get the width & height, if null , do the same test on each child , if one child returns a true value , break out of your loop and return the width & height of the child's mask. Of course, this won't work too well if several children use masks, in such case , you could try to find which mask is bigger...

PatrickS
A: 

If there are no crossdomains issues and the content is not too big (BitmapData has a size limitation), this should work:

function handleComplete(e:Event):void {
    var bmd:BitmapData = new BitmapData(loader.width,loader.height,true,0);
    bmd.draw(loader);
    var rect:Rectangle = bmd.getColorBoundsRect(0xff000000,0xff000000,true);
    trace(rect);
}

This will get you the rectangle enclosing all pixels whose alpha value is 0xff (fully opaque).

Juan Pablo Califano