I keep getting this error when attempting to addChild to a component that is second container in a viewstack and at the same time selecting the selectedChild of the viewstack to the second component.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
The problem
When we set the selectedChild of the viewstack, the children of the component selected will start to create the children. However, i wanted to add children display objects into one of the child display objects in the component. So the errror is thrown.
My quick solution is to play around with the creationEvents in Flex(Reference below). The idea is to call creationComplete once the display object to update has been created. And another function on the component to update the children again. I needed to remove the child display objects and then add new ones to it. Ok i might not be clear but i wonder who reads this.
The update function will then be called again. There will be an extra check:
if (this.[id of displayObject] == null ) { do nothing } else { update the display object }
Reference
- http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=containers_intro_063_12.html
#1 by gary on July 23, 2008 - 6:16 am
Quote
you mentioned wondering who reads this… well I was trying to figure out why i couldn’t set the value in a textfield for the second form in a viewstack control i had on a flex tilewindow. Your entry led me to looking at the creation policy settings… THANKS!!!
#2 by Ted on July 23, 2008 - 3:43 pm
Quote
Glad to be of help, gary… Feel free to drop by to share any questions or problems…
#3 by antonic on October 7, 2008 - 2:56 am
Quote
i needed to see this post to understand what caused my NPE, after battling for an hour. what i don’t understand is why they mention in the livedocs that viewstack children objects do exist, but are not just visible. thanks for your valuable help.
#4 by Stephen Stulov on October 15, 2008 - 9:51 pm
Quote
This one was realy weird for me fisrt time I met ViewStack too. I thought ViewStack is like some kinda “visibility manager” of its children to let only one be visible. Finaly I decided just to use canvas and control visibility myself)
#5 by Kenneth on October 15, 2008 - 11:30 pm
Quote
@Stephen
just curious, how are you using canvas to control visibility? I hope its not putting everything into the canvas and toggling their visibility. This approach may not be wise if you have a Flex app with many views, potential mem leakage. ViewStack is sorta like a book of views; you turn the “pages”(views) by changing the selectedIndex. The creation of the views are by default created only when viewed.(You can also set different creationPolicy though). Your approach seem to create everything at one go.