I am using Flex 2.

Steps:
1. Add a Phase (P1) 
2. Add another Phase P2 (P1's child)
3. Expand the Phase (P2)
4. The application crashes

The tree should look like:
-Project
--P1
---P2

Thanks

Stack
--------
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
        at mx.controls::Tree/::buildUpCollectionEvents()
        at
mx.controls::Tree/http://www.adobe.com/2006/flex/mx/internal::onTweenEnd()
        at mx.effects::Tween/endTween()
        at mx.controls::Tree/mx.controls:Tree::updateDisplayList()
        at mx.core::UIComponent/validateDisplayList()
        at mx.managers::LayoutManager/::validateDisplayList()
        at mx.managers::LayoutManager/::doPhasedInstantiation()
        at Function/http://adobe.com/AS3/2006/builtin::apply()
        at mx.core::UIComponent/::callLaterDispatcher2()
        at mx.core::UIComponent/::callLaterDispatcher()
        at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
        at flash.utils::Timer/flash.utils:Timer::tick()


--- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> The branch expanded just fine for me in Flex 3.  In the future it
will help if you can simplify the test case even further and provide
explicit steps to reproduce the problem  Showing the entire stack
trace is also helpful.
> 
> ________________________________
> 
> From: [email protected] [mailto:[EMAIL PROTECTED]
On Behalf Of César P.
> Sent: Tuesday, November 27, 2007 6:53 AM
> To: [email protected]
> Subject: [flexcoders] Problems with a Tree and dynamic data provider
> 
> 
> 
> Hi,
> 
> I'm new to Flex and to the group. I came here because I am having
> problems with a Tree control and a dynamic data provider.
> 
> The problem is that everytime I try to expand a branch with no children
> the application crashes with a #1009 error. Is it the expected
> behaviour? I don't know how to fix it or if there is something wrong
> with my code that produce this bug.
> 
> Also which one is the best strategy to remove nodes from this Tree.
> 
> I'm a Java Developer but we are going to do a project with Flex so I am
> learning.
> 
> Here is my code, I'm learning so everything is in my mxml application :P
> .
> --------------------
> <?xml version="1.0" encoding="utf-8"?>
> <!-- Tree control example. -->
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> ">
> 
> <mx:Script>
> <![CDATA[
> 
> import mx.collections.XMLListCollection;
> import mx.controls.Alert;
> import mx.collections.Sort;
> import mx.collections.SortField;
> 
> [Bindable]
> private var project:XML =
> <list>
> <phase title="Project" isBranch="true">
> </phase>
> </list>;
> 
> [Bindable]
> private var companyData:XMLListCollection = new
> XMLListCollection(project.phase);
> 
> private function treeLabel(item:Object):String
> {
> var node:XML = XML(item);
> 
> if( node.localName() == "phase" )
> {
> return [EMAIL PROTECTED];
> }
> else
> {
> return [EMAIL PROTECTED];
> }
> }
> 
> private function isPhase(node:XML):Boolean
> {
> if(node.attributes()[1].toString() == "true")
> {
> return true;
> }
> 
> return false;
> }
> 
> private function addPhase():void {
> 
> var listNode:XMLList;
> 
> var currentNode:XML = XML(myTree.selectedItem);
> 
> var newNode:XML = <phase></phase>;
> 
> [EMAIL PROTECTED] = inputPhase.text;
> 
> [EMAIL PROTECTED] = "true";
> 
> if(currentNode != null && isPhase(currentNode) &&
> inputPhase.text != "")
> {
> listNode = XMLList(currentNode);
> 
> listNode[0].appendChild(newNode);
> }
> }
> 
> private function addTask():void {
> var listNode:XMLList;
> 
> var currentNode:XML = XML(myTree.selectedItem);
> 
> var newNode:XML = <task></task>;
> 
> [EMAIL PROTECTED] = inputTask.text;
> 
> [EMAIL PROTECTED] = "false";
> 
> if(currentNode != null && isPhase(currentNode) &&
> inputTask.text != "")
> {
> listNode = XMLList(currentNode);
> 
> listNode[0].appendChild(newNode);
> }
> }
> ]]>
> </mx:Script>
> 
> <mx:Panel id="panel" title="Tree Control Example" height="85%"
> width="75%"
> paddingTop="10" paddingLeft="10" paddingRight="10"
> paddingBottom="10">
> 
> <mx:Label width="100%" color="blue"
> text="Select a node in the Tree control."/>
> 
> <mx:HDividedBox width="100%" height="100%">
> <mx:Tree id="myTree" width="50%" height="100%"
> labelField="@label" labelFunction="treeLabel"
> showRoot="false" dataProvider="{companyData}" />
> </mx:HDividedBox>
> <mx:HBox>
> <mx:Button id="phaseButton" label="Add Phase"
> click="addPhase();" width="74"/>
> <mx:TextInput id="inputPhase"/>
> </mx:HBox>
> <mx:HBox>
> <mx:Button id="taskButton" label="Add Task"
> click="addTask();" width="74"/>
> <mx:TextInput id="inputTask"/>
> </mx:HBox>
> </mx:Panel>
> </mx:Application>
> 
> -----------------------
> 
> Thanks
> 
> Cesar Perez
>


Reply via email to