开发者

In AS3, how to obtain visible size of loaded SWF that contains a mask?

I'm using UILoader to load SWF files which I have开发者_Python百科 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.


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).


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜