4 Replies Latest reply on Dec 8, 2008 6:28 PM by renatomoya

    Help w/ clicking on leaves of tree node

    999haliu
      Hello,

      I am fairly new to Flex and coding in general, so please bare with me if my problems seems like a trivial one.

      I am trying to create a tree list, where the contents of the tree are actually links. For example, the top level of the tree node would be a category (companies), and the leaves of the tree would be the company names. In addition, I would like the user to be taken, in a new browser window, to a URL specified in the XML list when clicking on a company name.

      I am having problems resolving the click actions in the app. I can get the app to open and close the nodes of the tree cleanly, but when I try to add some code to take the user to a URL when clicking on a company name (leaf), I get errors.

      I am really stuck on how to read the click event in the tree list, run to the associated XML file to find the URL, then open up a new browser page to that URL.

      Can someone help me please? I've added a snippet of code to review.

      Thank you in advance!
        • 1. Re: Help w/ clicking on leaves of tree node
          Level 7

          "hokudan" <webforumsuser@macromedia.com> wrote in message
          news:ghjqdk$i7n$1@forums.macromedia.com...
          > Hello,
          >
          > I am fairly new to Flex and coding in general, so please bare with me if
          > my
          > problems seems like a trivial one.
          >
          > I am trying to create a tree list, where the contents of the tree are
          > actually
          > links. For example, the top level of the tree node would be a category
          > (companies), and the leaves of the tree would be the company names. In
          > addition, I would like the user to be taken, in a new browser window, to a
          > URL
          > specified in the XML list when clicking on a company name.
          >
          > I am having problems resolving the click actions in the app. I can get the
          > app
          > to open and close the nodes of the tree cleanly, but when I try to add
          > some
          > code to take the user to a URL when clicking on a company name (leaf), I
          > get
          > errors.

          What are the errors?

          Note that
          var urlReq:URLRequest = new
          URLRequest(evt.currentTarget.source);

          will be null with the data that you're currently using, because none of your
          nodes have a source child node.

          HTH;

          Amy


          • 2. Re: Help w/ clicking on leaves of tree node
            999haliu Level 1
            Hi Amy,

            Thank you for your reply. Here are the errors that I'm getting in Flash:

            ReferenceError: Error #1069: Property source not found on mx.controls.Tree and there is no default value.
            at main/tree_itemClick()[/Users/admin/Documents/Flex Builder 3/IDQA page/src/main.mxml:27]
            at main/__myTree_itemClick()[/Users/admin/Documents/Flex Builder 3/IDQA page/src/main.mxml:88]
            at flash.events::EventDispatcher/dispatchEventFunction()
            at flash.events::EventDispatcher/dispatchEvent()
            at mx.core::UIComponent/dispatchEvent()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:9156]
            at mx.controls.listClasses::ListBase/mouseClickHandler()[E:\dev\3.1.0\frameworks\projects\fr amework\src\mx\controls\listClasses\ListBase.as:9035]
            at mx.controls::Tree/mouseClickHandler()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\c ontrols\Tree.as:2922]

            Two of the nodes in the tree also have a 'source' value that I've entered- do I need to make it a separate line instead of including it with the 'label' field?
            • 3. Re: Help w/ clicking on leaves of tree node
              Level 7

              "hokudan" <webforumsuser@macromedia.com> wrote in message
              news:ghk08n$pdb$1@forums.macromedia.com...
              > Hi Amy,
              >
              > Thank you for your reply. Here are the errors that I'm getting in Flash:
              >
              > ReferenceError: Error #1069: Property source not found on mx.controls.Tree
              > and
              > there is no default value.

              > Two of the nodes in the tree also have a 'source' value that I've entered-
              > do
              > I need to make it a separate line instead of including it with the 'label'
              > field?

              Two things:

              1) I'm thinking the currentTarget of the itemClick event will be the tree
              itself, not the node. So you need to look at the selectedItem property to
              get the node. See the example under Handling Tree control events:
              http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html

              2) To answer your question, you just need to reference it properly for
              however you set up the xml:
              http://dispatchevent.org/roger/as3-e4x-rundown/


              • 4. Re: Help w/ clicking on leaves of tree node
                renatomoya
                hokudan,

                You're going well, you just need to do this:

                1- Inside the 'tree_itemClick' method, you need to parse the object like this:

                var item:Object = evt.currentTarget;
                item.selectedItem.@label // This will retrieve the label of the selected item.

                For attributes, use @.

                I hope this helps.