10 Replies Latest reply on Dec 19, 2007 8:12 AM by BigBenFly08

    not able to pass values to variables in extended Tree class

    lucky_raga
      Hi,

      I have a as class that extends from Tree, additionally this custom class defines
      new class level variables as follows:

      public class MyTree extends Tree {

      public var arrayColl:ArrayCollection;

      }

      and i call this tree from mxml as follows:

      <customTree:MyTree
      arrayColl={list}
      xmlns:customTree="../../.*"/>

      Though my 'list' collections is not null, when i place an alert in the constructor of extended tree class
      it shows as null.
      Please advice.

      Thanks,
      Lucky
        • 1. not able to pass values to variables in extended Tree class
          dietmar.paulus Level 1
          Try this app:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
          <local:MyTree dataProvider="{dp}"/>
          <mx:ArrayCollection id="dp">
          <mx:Object label="HALLO"/>
          </mx:ArrayCollection>

          </mx:Application>

          package
          {
          import mx.controls.Tree;
          import mx.collections.ArrayCollection;

          public class MyTree extends Tree
          {
          public function MyTree()
          {
          trace("CONSTRUTOR");
          }

          override public function set dataProvider(value:Object):void
          {
          trace("SET DP");
          super.dataProvider = value;
          }
          }
          }

          this should work, and you also will see, that the constructor is called befor you set the dataProvider, so it will always be null in the constructor
          • 2. Re: not able to pass values to variables in extended Tree class
            lucky_raga Level 1
            the override method in the custom class that extends Tree class is not getting called at all.
            Any idea.
            Please suggest.

            thanks,
            Lucky
            • 3. Re: not able to pass values to variables in extended Tree class
              dietmar.paulus Level 1
              When I start the app, the tree shows one label (which is hallo) and the output is
              CONSTRUCTOR
              SET DP

              by the way: trace() outputs only are shown when you debug the application, maybe this is the reason, why you think the override method is not called
              • 4. Re: not able to pass values to variables in extended Tree class
                lucky_raga Level 1
                this is wat i had...

                override public function set dataProvider(value:Object):void {
                treeList = ArrayCollection(value);
                Alert.show("passed tree: " + treeList.length);
                // form the xml tree to be displayed
                formXMLTree();
                super.dataProvider = tree;
                // did not get any alert pop up.
                }

                by the way, i am stuck with a strange problem, no idea why it is happening like this...
                i have a mx:Canvas
                <mx:Canvas http=....>
                <mx:Script>
                var collection:ArrayCollection;

                public function formCollection():void {
                collection.addItem(object); //upto 11 objects.
                // in here if i Alert.show(collection.length); it shows correctly as 11 items.
                }
                </mx:Script>
                <customTree:MyTree
                dataprovider={collection} // here the collection is null.
                />

                Why is it so...
                Please advice.

                Thanks,
                Lucky
                • 5. Re: not able to pass values to variables in extended Tree class
                  dietmar.paulus Level 1
                  can you please post all the code you have!
                  • 6. Re: not able to pass values to variables in extended Tree class
                    lucky_raga Level 1
                    below is the canvas:

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml">
                    <mx:Script>
                    <![CDATA[
                    import mx.collections.IViewCursor;

                    import mx.collections.ArrayCollection;
                    import com.citi.ascript.TreeData;
                    import mx.controls.Alert;
                    import com.citi.ascript.CitiTree;

                    public var availableTreeDataColl:ArrayCollection;
                    public var selectedTreeDataColl:ArrayCollection;
                    public var treeData:TreeData;
                    public var srcTree:CitiTree;

                    public var availableTreeDataArray:Array = [{a:1},
                    {b:2},
                    {c:3}
                    ];

                    public function formTreeData():void {
                    var tempColl:ArrayCollection = new ArrayCollection(availableTreeDataArray);
                    availableTreeDataColl = new ArrayCollection();
                    for (var i:int=0; i<tempColl.length; i++) {
                    var tempTreeData:Object = tempColl ;
                    treeData = new TreeData();
                    treeData.a = tempTreeData.a;
                    treeData.b = tempTreeData.b;
                    treeData.c = tempTreeData.c;
                    availableTreeDataColl.addItem(treeData);
                    }
                    }
                    ]]>
                    </mx:Script>
                    <mx:VBox>
                    <mx:Label text="Drag &amp; Drop the analysis sections
                    that you would like to include in the report" width="450" height="20"/>
                    <mx:HBox id="treeContainer" creationComplete="formTreeData();">
                    <customTree:MyTree treeList={availableTreeDataColl} // here collection becomes null.
                    </customTree:MyTree>
                    </mx:HBox>
                    </mx:VBox>
                    </mx:Canvas>

                    The collection of TreeData is iterated in the customTree to form xml which will act as dataprovider for tree.

                    and this canvas is added as a child for a panel in my main application.

                    Hope this gives an idea.

                    Thanks,
                    Lucky
                    • 7. Re: not able to pass values to variables in extended Tree class
                      dietmar.paulus Level 1
                      maybe you can try and define the availableTreeDataArray in mxml:
                      <mx:Canvas>
                      ...
                      <mx:Array>
                      <mx:Object a="1"/>
                      <mx:Object b="2"/>
                      <mx:Object c="3"/>
                      </mx:Array>
                      ...
                      </mx:Canvas>
                      • 8. Re: not able to pass values to variables in extended Tree class
                        lucky_raga Level 1
                        ok, but any idea why the variable (collection) becomes null while passing as a parameter to
                        the custom component or mx component.
                        I am surprised though with this behavior.

                        Thanks,
                        Lucky
                        • 9. Re: not able to pass values to variables in extended Tree class
                          dietmar.paulus Level 1
                          i try a guess:

                          I think that the treeList={availableTreeDataColl} is made before the availableTreeDataColl is filled with data.
                          Normally this should not matter because with the brackets you make it value binding, but value binding is not working with Arrays I think, try to use ArrayCollection as Datatype for the availableTreeDataColl

                          But as I said, it is just a guess
                          • 10. Re: not able to pass values to variables in extended Tree class
                            BigBenFly08
                            Before you assign your list to the dataProvider property, make sure your formTreeData() function gets call. To do this, you can put creationComplete=formTreeData() in your mx:Application tag.

                            Also, my personal preference for accessing and retrieving variables from class is:

                            public class MyTree extends Tree {

                            private var arrayColl:ArrayCollection;


                            public function set ArrayColl(value:ArrayCollection) : void
                            {
                            arrayColl = value;
                            }

                            public function get ArrayColl() : ArrayCollection
                            {
                            return arrayColl;
                            }

                            }

                            But again, it's just my personal perferences.