7 Replies Latest reply on Dec 10, 2008 12:55 PM by ntsiii

    XML and creating links

    scc_web
      I'm new to flex and relatively new to XML (my background is mostly in PHP/MySQL) but I'm trying to build a navigation menu for a site using Flex (wanted to use Flash for animation purposes, heard this might be a better way to go). So far, it's going well, but I'm hung up on an issue. I want to be able to put all the links into a db and have an XML document generate them and then load into the Flex menu. So far, I can load the XML data ok, but I'm hitting a snag.

      Each link when I put it in the menu statically is using CDATA inside an <mx:htmlText> to generate the <a href=""> code. How can I put my xml data inside that? So, example <a href="{xml data for url}">{xml data for label}</a>. I also want the Flex to be able to loop that so that it doesn't have to be a fixed number of links. Make sense?

      Is there a better way to do it that using htmlText? I'm basically teaching myself Flex using a few books and web resources!

      Once I get the text navigation down, I want to build an app that will display images in a fade in fade out rotation. Each of the images will need to be pulled from the db and link (url also pulled from the db). Make sense?

      all of this would be really easy for me to do using php, but we want the animation that you can have with using flex.
      thanks!
        • 1. Re: XML and creating links
          rtalton Level 4
          I haven't seen this done, but I'll be watching this thread!

          Only way I've ever used is to just have only the text for the url in the xml, like:
          <menuitem label="Google's web site" url=" http://www.google.com"/>
          Then in the click handler for the menuitem, use navigateToURL to open a new browser window:
          navigateToURL(new URLRequest(event.target.menuDataProviderXML.url),'_blank');

          Hope this is useful to you at some point.
          • 2. Re: XML and creating links
            scc_web Level 1
            So, in your example, how do you handle the menuitem in Flex? Do you use a button? Some other object? What does your code look like? That might work for me (well, I don't know about for the images, but...)
            • 3. Re: XML and creating links
              Gregory Lafrance Level 6
              I'm wondering if you are using a Repeater to actually create the menu items. If so, I would imagine you could piece together the htmlText property of the current Repeater item with something like htmlText = "<a href=" + {myRepeater.currentItem} + ">" + myRepeater.currentItem + "</a>".
              • 4. Re: XML and creating links
                rtalton Level 4
                To handle a menuitem click, you'd use the "itemClick" event of the menuBar component.
                To handle clicking on a top-level menuBar item (what you see before expanding a menu), you'd use the menubar's "click" event.
                The menu and menuItem are actually two different things to a menuBar component, hence the two different events.

                No need to use a button. Just use a listener for the itemClick event, grab the associated url, and then navigateToUrl.
                • 5. Re: XML and creating links
                  scc_web Level 1
                  quote:

                  Originally posted by: Greg Lafrance
                  I'm wondering if you are using a Repeater to actually create the menu items. If so, I would imagine you could piece together the htmlText property of the current Repeater item with something like htmlText = "<a href=" + {myRepeater.currentItem} + ">" + myRepeater.currentItem + "</a>".


                  That sounds like exactly what I want to do. I've read about the Repeater and tried to do it, but I'm having trouble with the htmlText. It won't let me use a "<" character unless I encloses it in CDATA, but then I can't use the xml info...
                  • 6. Re: XML and creating links
                    ntsiii Level 3
                    Create a custom component for your link. Pass currentItem into it via a public property, probably a setter function. In that function, build the htmlText string.

                    Here is an example that does part of the. It is very old and I would do it differently now, but it might be of use.

                    http://www.cflex.net/showFileDetails.cfm?ObjectID=595

                    Tracy
                    • 7. Re: XML and creating links
                      ntsiii Level 3
                      And here are some Repeater snippets.
                      Tracy