Jump to content
Search Community

AutoFitArea - Error #2004 [SOLVED]

flysi3000 test
Moderator Tag

Recommended Posts

Hi, I decided to take AutoFitArea for a spin, but I'm getting the following on compile:

 

ArgumentError: Error #2004: One of the parameters is invalid.
at flash.display::Graphics/drawRect()
at com.greensock.layout::AutoFitArea()
at home/loadRandomBgImage()
at home/parseXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

 

Anyone else experiencing this? Thanks in advance,

 

Simon

Link to comment
Share on other sites

Hey, thanks for the speedy response. My code's below:

 

function loadRandomBgImage():void
{
// create a random number
bgNum = Math.floor(Math.random() * maxBg-1) + 1;

// choose a random image from the background image array
currBg = bgList[bgNum].@filePath;

// load the image
bgLoader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bgLoaderHandler);
bgLoader.load(new URLRequest(currBg));

// add the image to the bgHolder sprite
bgHolder = new Sprite();
bgHolder.addChild(bgLoader);

bgArea = new AutoFitArea(this, 0, 0, WIDTH, HEIGHT);
bgArea.attach(bgHolder, ScaleMode.PROPORTIONAL_INSIDE, AlignMode.CENTER, AlignMode.CENTER);
bgArea.addEventListener(Event.CHANGE, areaUpdate);

setChildIndex(bgHolder, 0);
}

 

Thanks again for your help.

Link to comment
Share on other sites

Please describe what type of object "this" refers to and what values WIDTH and HEIGHT are specifically. WIDTH and HEIGHT aren't zero are they?

 

If you could post a super-simple example FLA that demonstrates the problem, it would be extremely helpful. It doesn't need to be your production FLA file - just something very simple. (don't forget to zip the file before posting)

Link to comment
Share on other sites

Hey,

 

Thanks again for your help on this. I used "this" intending it to be the main DisplayObject (really, I was basing it off of the example in the AsDocs). WIDTH and HEIGHT are the width and height of the stage. Basically, I'm trying to get an image to fill the browser background and scale proportionally. I've gotten this working in the past, in my own kludgy way, but wanted to use this since it seems so much cleaner.

 

Interestingly, I get a new error when I publish my stripped down fla file - now, I get the following:

 

Error: The parent of the DisplayObject instance3 added to AutoFitArea instance5 doesn't share the same parent.
at com.greensock.layout::AutoFitArea/attach()
at test_fla::MainTimeline/loadRandomBgImage()
at test_fla::MainTimeline/frame1()

 

I know it's something really simple, and I really do appreciate your help.

Link to comment
Share on other sites

As the documentation indicates, the attached objects must share the same parent as the AutoFitArea, and you were using bgHolder as the parent for the AutoFitArea but the root for the parent of your attached object, bgImage. The other problem is that when you attached your bgImage, it had no size at all because the image hadn't loaded yet. So when AutoFitArea tried to do its work, it had no data to work with regarding height and width. All you needed to do was add an update() call when your image finishes loading so that AutoFitArea could look at it again and do its magic.

 

I've attached a corrected fla.

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