Tuesday, May 20, 2008

scale9Grid AS3 Troubleshooting ArgumentError

I had to use the scale9Grid for the first time today to maintain some rounded borders. I really did not put much thought into it... thinking I already understood the concept from design work. Ouch, I should have read the help file a little more thoroughly before I just started coding.

I am going to assume you understand the basic concept of scale9Grid and focus on the main pitfall I stumbled into today. If you do not understand the basic concept, please check the Flash help file first.

Each time I tried to call scale9Grid I received an ArgumentError. At first I thought I may have been passing in a bad rectangle or that I could not use the scale9Grid on my custom movie class. Turns out, my rectangle was fine but it did not fall within the movie I was trying to scale. I had part of it either outside of or right on the border of the movieClip. If this happens, the ArgumentError will be thrown. So make sure that your x, y, width, and height of the rectangle all fall within the target MovieClip.

Other thoughts that may help:
I found it best to set the scaleX and scaleY to 1 before trying to create the rectangle. Otherwise the item may still be scaled from the previous scale9Grid call and the rectangle could get out of whack.

I also found it helpful to place the origin/reference point of the movieclip to 0,0.

Hope that helps.


Blake said...

I'm running into this error, too -- and I KNOW my rectangle is where it's supposed to be: Just to test things, I checked "Enable 9-slice" in my symbol's properties and positioned the slices accordingly; I then traced the object's grid and got identical results to what I'd been trying to set manually! And the actual slices didn't do anything to prevent unwanted distortion...

Of course, I'm treating the top left as my symbol's registration point...I'm gonna go mess with that some more...

Argh! No change!!! Any suggestions?!

Blake said...

Bleargh! All right, further experiments indicate that if you have a symbol made of up multiple other symbols, the scale9grid goes straight down the pooper. :(

I would love to be contradicted here... :(

Ickydime said...

I haven't run into that personally. So you are saying that if you have a MovieClip with no children it does scale9 fine, then when you add 1 child to the movieclip and it will no longer work?

I noticed it quits working when you add a mask as shown in a later post I wrote. But can't recall if I have ever had nested children being scaled.

James said...

Can't speak to the child MCs just yet but regarding the coordinates, I had the same problem and came here from google... thanks BTW, save me some hair pulling.

My scenarios worked out... it was a rounded rectangle and I hadn't thought about the fact that I had to double the grid inset from 0,0, etc to account for the corner radius...well I don't think you have to double it, just account for it... so at least 1px more inside.

Anonymous said...

I just came across the same problem. If you try to apply a scale9grid to any display object that has nested MovieClips, it breaks the scaling.

That's crap. Hope this is fixed in an update.