Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
tcoz

Index Out of bounds for mx TextAreas, Text, etc.

Recommended Posts

Hey there, I'm trying to run the sample. (FYI I'm an experienced Flex dev, so I have a feeling I'll feel dumb when you answer this...)

 

 

I run it, and I get this stack trace (truncated to relevant gs class). This is true of mx Text, TexArea, etc. However, other images, canvases, etc. are fine, and I can even add a textarea or text to that canvas. But I can not add a TextArea, as is, without getting the index error. I'm fully aware of the hierarchy and requirements of the display list, but this is the code from the sample, so I'm assuming it should work.

 

Any insight?

 

RangeError: Error #2006: The supplied index is out of bounds.

at flash.display::DisplayObjectContainer/addChildAt()

at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()[E]

at mx.core::Container/addChildAt()[E]

at gs.transform::FlexTransformManager/addChildAt()[/Applications/MAMP/htdocs/workspace_flex/DessyMoodBoard/src/gs/transform/FlexTransformManager.as]

Link to comment
Share on other sites

Hmm. I copied/pasted your code into a sample Flex app and it worked great (well, I just had to adjust the image path, that's all). I wonder if you're using a mismatched version of FlexTransformManager and TransformManager or something odd like that? What version(s) are you using? Is that the only code in your Flex app or do you have other stuff going on? What version of the Flex SDK are you using?

Link to comment
Share on other sites

There's nothing else going on, again if I just swap the TextArea for an image, or anything else that's a standard IUIComponent, it works fine. The issue appears to be that these are not IUIComponents.

 

I'm using Flex 3.1. This issue is pretty serious, the client provided me with the license and sort of expected it to "just work".

Link to comment
Share on other sites

I'll keep posting my findings:

 

I was attempting to run this in debug; for the heck of it, I ran it in non-debug, and it works as expected. This is of course is an issue; have to be able to run the app cleanly in debug.

 

Note that this is an issue in the sample as well (imported directly without any manipulation into Flex Builder 3 using the 3.1 sdk). I'm working with the FlexTransformManager class now to see if I can fix, from what I can see though, this is likely a bug in the class.

Link to comment
Share on other sites

The issue appears to be that the transform manager adds a series of IUI objects apart from the request to add the text component itself. It adds a total of 3 objects; the original request, another one (which I gather you use to probably solve some scaling issues), and then a third; it is this third object that causes the debugger to balk with an index out of range error. Interestingly, when not run in debug, the app proceeds, no doubt without adding the third object; this needs to be handled evidently.

 

Preliminarily, this code fixes it. You just check to make sure that the index is available before you add the object, if it isn't, just return null. Although I haven't gone all the way throught it, the stack must check for that null value and short circuit the operation, so the error is handled and the app can continue to run cleanly.

 

I don't know if this will effect the app otherwise, but at this point it seems to be working.

 

At the FlexTransformManager class, at line 255, edit the function like so:

 

override public function addChildAt($child:DisplayObject, $index:int):DisplayObject

{

var mc : DisplayObject;

if ( $index < super.getChildren ( ).length )

{

mc = super.addChildAt($child, $index);

autoAddChild($child);

}

return mc;

}

Link to comment
Share on other sites

Unfortunately, this code doesn't fix the problem entirely. The text field wrapper that allow it to be moved/scaled (which I now assume is the third displayobject being added) gets deprecated, so you can't move/scale the text field.

 

This however, does appear to be a usable workaround. Leave the code of the transform manager alone (though it seems there is an issue with it somewhere), and just set up your objects like this, notice that I have wrapped the TextArea in a canvas, and have used the width/height/x/y in the canvas, ommitting the x/y from the TextArea (though still keeping the width/height).

 

When I do the below, the provided FlexTransformManagerSample now appears to work in all regards, though note that any scaling restrictions will now need to be passed to the canvas, not the TextArea.

 

Link to comment
Share on other sites

Hm. I'm baffled. Three problems:

 

1) Your proposed code doesn't accommodate adding a child at the top level. In other words, if there are 3 children currently and you want to add a 4th (at index 3), your code would prevent it (index 3 is not less than the current number of children, 3).

 

2) I cannot for the life of me reproduce this problem even in the debugger and nobody else has reported the problem. Maybe there's an issue with your Flex install? I'm grasping here, I know. Could you export your Flex project that demonstrates the error and e-mail it to me? You said it happens on my sample that comes with the code too, right? But like I said, I cannot get any errors whatsoever.

 

3) You said you're adding non-UIComponents? I'm pretty sure Flex won't allow that. Only UIComponents can be added to a Canvas. It's an admittedly [extremely] annoying requirement in the Flex framework, but it's not related to TransformManager.

Link to comment
Share on other sites

  • 1 year later...
have you tried it?

Of course.

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