This content has been marked as final. Show 12 replies
What error do you get? This looks ok - clearly the addDesignView and compAboutUsView don't do anything, but I wouldn't expect an error. The actual error might give some hints, though.
Thanks for looking at this Tim.
The error I get is:
Error: Cannot add a child that is already parented.
at mx.core::UIComponent/set currentState()
You can see that this code is extremely simple. Just switching between states.
The problem seems to happen if a state is based on something other than base state. My states are:
I can switch between views that are based on the base view and no errors.
When I switch between the two states adDesignView (linkButton Advertise) and compAboutUsView (linkButton Company) the first time I can see that the color change for the linkbutton does not happen. I assume this is where the initial error occurs.
If I keep clicking on these two linkbuttons I will get the above error.
I can move the code from the ourCompanyView into its related state of compAboutUsView and do the same with the Advertise states and the error goes away.
Also if I make all the states based on the base state the problem disappears. However this forces me to create duplicate objects that could be contained in a parent state.
I understand that in changing states that flex will first change to the base state and then change to the desired state.
Maybe I dont understand how to change between states that are not based on the base state.
I also see that if I switch states by first changing to the views parent and then to the view it will work with no errors.
For example, the following works:
The ourCompanyView is based on the base state.
Is this the way I am supposed to change views that are not based on the base state?
Very weird - you're not attempting anything that shouldn't work. I tried your example and get the same problem. The error happens because it's attempting to add back a panel that it never removed. You can see that moving from adDesignView to compAboutUsView fails to remove the panel added by adDesignView - which it should do.
This is a flex bug I would have to say. If you're feeling really energetic you could step through the UIComponent code in the debugger and see why it's not removing the added components.
OK, I was feeling energetic. The error is at line 6530 of UIComponent.as. The loop looks like this:
while (firstBaseStates[firstBaseStates.length] ==
commonBase = firstBaseStates.pop();
if (!firstBaseStates.length || !secondBaseStates.length)
Its purpose is to work back through the arrays of parents looking for the last common base. Problem is that the last element of an array, X, is
X[X.length - 1]
So if someone at Adobe could fix it you'd be good to go. Meanwhile, set the state back to base first, and then to your desired state. If you have transitions this could be more challenging, but there are ways 'round it.
Thanks for taking a look at that.
I suspected it might be a bug but it seemed to big and obvious of an error to have been missed by Adobe QA.
I am just getting into transitions now and may hit you up for some tips later. I can see how this flex bug will add a challenge.
Thanks for your help.
If you do get to using state transitions, note that if you use the setCurrentState method to change states, you can specify in an optional second parameter whether or not you wish to run you transition effects.
Flex is great - nothing you can do in any presentation technology that you can't do in flex/flash, provided you stay in 2D.
I got such an error just like you.
Now since it is a bug, then I don't need to try to find some solutions.
JUST AS FlightGuy had pointed that,
the findCommonBaseState method in the UIComponent.as has such bug:
while (firstBaseStates[firstBaseStates.length]) == secondBaseStates[secondBaseStates.length])....
Obviously, the code is over bounds of Array, which is a funny bug, is it?
So, if there exits more than one deepth state level, the findCommonBaseState will return a WRONG value. That is!
Really hope this BUG can be resolved in the next patch OR version.
I just ran into the same problem, I have solved it now by setting the state back to te base state as Flyguy suggested, but like Flyguy I see a problem in this when I want to use transitions in the future. I hope adobe will fix the problem before I will build in te transitions. But 3 months have already past since the first user figured out the problem....
I confirm that findCommonBaseState returns a WRONG value in Flex 2.0.1 SDK when switching between states that are dependent on other states by relying on "basedOn" property
I thnk that the problem is associate to an Object that is being added to a parent, which has been added before. so in the problem throws this error, you need before adding this component remove the component from the parent to which you are adding and after that add the component, I get the same problem and figure out this a solution