Jump to content
Search Community

Getting started with AutoFitArea

JayP test
Moderator Tag

Recommended Posts

Hi Jack,


First off, thanks for all your work. I've been trying to get the AutoFitArea to work, but I'm having a problem. I am trying to attach a MovieClip to the AutoFitArea, but I am getting an error. In just trying to get started, I am using your sample AS3 code from the site, and I keep getting an Error 1047: Parameter initializer unknown or is not a compile time constant.


In looking at the sample code I needed to instantiate the 'myImage' to something, so I instantiated myImage to a MovieClip object (linked in my .swc) but I think this is causing a problem. Is there something I am missing about the DisplayObject and what the requirements are for it. I'm just a little confused and could use a shove (or kick) in the right direction. I can see that others are using these classes for Flex projects, but I am not sure what the error means or how to get around it.


When I saw the AutoFitArea, I thought this is exactly what I need because one of the downsides of Flex seems to be the scaling of flash assets inside Flex containers. I intended to use the AutoFitArea inside a Flex container so my UI can scale the clip while maintaining aspect ratio.


Like I said, I may be misusing the AutoFitArea altogether, so if that is the case, I apologize for wasting your time. Keep up the good work, and thanks a bunch for all you've done already.

Link to comment
Share on other sites

Hm, I'm not sure - could you post an example that demonstrates the problem? It's tough to troubleshoot blind.


I wonder if the problem is simply that Flex requires that any object that you're adding to a UIComponent be a UIComponent, whereas AutoFitArea is a simple Shape. Frankly, I didn't intend for AutoFitArea to be used in Flex, but it shouldn't be too difficult to make some tweaks to get it going there too.

Link to comment
Share on other sites

  • 3 months later...

I had the same problem in Flash Builder. Apparently the Flex compiler doesn't like variables as parameter initializers. Just change the initial values in the parameters from constants to their string value equivalents.




Throws errors in method parameters: scaleMode:String = ScaleMode.PROPORTIONAL_INSIDE

Doesn't throw errors in method parameters: scaleMode:String = "proportionalInside"


Below is a full example that won't throw errors:


public static function createAround(target:DisplayObject, scaleMode:String = "proportionalInside", hAlign:String="center", vAlign:String="center", crop:Boolean=false, minWidth:Number=0, minHeight:Number=0, maxWidth:Number=999999999, maxHeight:Number=999999999, previewColor:uint=0xFF0000, calculateVisible:Boolean=false):AutoFitArea

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...