7 Replies Latest reply on Aug 22, 2008 10:17 AM by Developer504

    navigateToURL from XML data

    Developer504 Level 1
      (Edited for clarity 13:16 CST)

      Ok thanks to Greg, I have this barchart with a re-direct built in:

      This is my simple barChart:

      <mx:BarChart x="561" y="198" id="CapitalExpenditures" dataProvider="{ceDs}" width="762" showDataTips="True" fontSize="12" height="371">
      <mx:verticalAxis>
      <mx:CategoryAxis categoryField="@type" />
      </mx:verticalAxis>
      <mx:series>
      <mx:BarSeries displayName="Expense" xField="@balance" fill="{sc1}" stroke="{s1}" labelFunction="formatNumber"
      click="navigateToURL(new URLRequest(rptWebsite))">
      </mx:BarSeries>
      </mx:series>
      </mx:BarChart>

      This works fine, but rather than hard-code the URL, I want to get it from XML data which is already loaded into the system and assigned to an XMLList "ceDs". My XML file is structured like this:

      <projects>
      <job prName="A-Project" hours="705.50" rptUrl=" http://www.google.com"/>
      <job prName="B-Project" hours="370.00" rptUrl=" http://www.yahoo.com"/>
      </projects>

      What I want to do is use the URL in this XML file, under the name rptUrl, as the URL path in my re-direct.

      I tried just putting in navigateToURL(new URLRequest(@rptUrl )"> in but that failed to compile.

      My confusion is the where to insert the value into the URL variable, and precisely what syntax to use? Do I need to use e4X for example?

      I created this function for my redirect:

      public function goUrlTFP(event:MouseEvent):void
      {
      rptWebsite=" http://www.google.com"
      return navigateToURL(new URLRequest(rptWebsite))
      }

      This compiles, but I get nothing in the variable.

      Am I using the wrong syntax? Do I need to make my function something other than a mouseEvent? Should I trigger the function somewhere else than at the click event? Do I need to loop through the file and populate an XMLList or something?

      I tried rptWebsite=item.@rptUrl and rptWebsite=ceDs.@rptUrl but those failed to compile

      M.
        • 1. Re: navigateToURL from XML data
          VarioPegged Level 2
          M, without trying to sound like I'm raggin' on you (again), I'm curious how you go about sleuthing your way through the API to come up with possible solutions. What is your thought process? I'm wondering if it wouldn't benefit you more if you are provided some tips on how to use the API properly. Teach you to fish instead of giving you the fish, (to adjust the proverb a little).

          I certainly didn't know the answer to your problem just a few minutes ago, but that's literally what it took me to find what I think may be an answer to your problem.

          You've defined your functionality as:
          Click a bar chart and have it redirect to a URL that's available in the dataProvider for the BarChart.

          How can we get to that URL data? The first thing to check would be click events. We look at the possible events that can be dispatched when either clicking on the chart element (BarSeries) or the BarChart component itself. When looking at the "click" event for both I wasn't expecting much as far as that event carrying additional information that I might be able to use, it's just a plain click event. And if I did event.currentTarget, there's no property that directly gives me the data I'm seeking. However, in the API I see an itemClick event of type ChartItemEvent (under Events) for BarChart that looks promising.

          Then I look in the API at ChartItemEvent and notice that there's a "hitData" property of type HitData that also looks promising. Now I look at HitData in the API and see that it has an "item" property. This more than likely is the item that's used to render the particular BarSeries I've clicked on. So I figure I can easily get the associated data on the itemClick event.

          I tried that and sure enough it got me the data I was expecting. I may have overlooked something painfully obvious and far simpler to get this data, but I think that this thought process shows that with just a little effort you can get some leads in the API that'll probably get you your solution. I doubt there's anyone on this forum that knows everything there is to know about the API. Use the docs, they're your friend.

          BTW, what's the other language that you're most familiar with that you mention now and again?

          TS
          • 2. navigateToURL from XML data
            Developer504 Level 1
            I have a background in something called magic eDeveloper, which you probably never heard of. It a high level database language used by large banking, insurance and some other industries.

            This is their website
            http://www.magicsoftware.com/

            Magic is basically a completely different paradigm from most of the more common software languages people use today. It's very sophisticated but development licenses are expensive and it requires runtimes. I'm very glad to have the chance to learn flex.

            I have gotten better at using the helps to understand the API, but I still find the overall paradigm somewhat confusing (like trying to use the wrong kind of event here) and the different kinds of syntax you need to use (e4x, actionscript, mxml etc.) that I still get derailed pretty routinely.

            Believe it or not though i actually am answering 80% of my own questions now by using the help or online examples / blogs etc. I hope that will soon increase to 99% because I have to do a lot of work in Flex lately.

            I appreciate your continued patience as I struggle up this learning curve. Once my researching process is more efficient I won't be asking so many stupid questions. Hopefully the ones i am asking now aren't quite as vague as they were a few months ago. Answers like yours here are actually very helpful for me to understand some of the key concepts / context so my research can be more effective.

            I think what seems like a forest of dead-ends to me is an obvious and easy path to a solution to you because you have developed a high degree of agility in parsing the available information and discarding what is meaningless or superfluous. I can do that with Magic very efficiently, in Flex I'm sometimes still flopping like a fish out of water. Hopefully that will improve.

            M.
            • 3. Re: navigateToURL from XML data
              Developer504 Level 1
              By the way, that worked, thanks.

              M.
              • 4. Re: navigateToURL from XML data
                Level 7

                "Developer504" <webforumsuser@macromedia.com> wrote in message
                news:g8ki4m$2cb$1@forums.macromedia.com...
                >I have a background in something called magic eDeveloper, which you
                >probably
                > never heard of. It a high level database language used by large banking,
                > insurance and some other industries.
                >
                > This is their website
                > http://www.magicsoftware.com/
                >
                > Magic is basically a completely different paradigm from most of the more
                > common software languages people use today. It's very sophisticated but
                > licenses are expensive and it requires runtimes. I'm very glad to have
                > the
                > chance to learn flex.
                >
                > I have gotten better at using the helps and the API, but I still find the
                > overall paradigm somewhat confusing (different types of events) and the
                > different kinds of syntax you need to use (e4x, actionscript, mxml etc.)
                > that I
                > still get derailed pretty routinely.
                >
                > Believe it or not though i actually am answering 80% of my own questions
                > by
                > using the help or online examples / blogs etc. I hope that will soon
                > increase
                > to 99% once I am having to do a lot of work in Flex.
                >
                > I appreciate your continued patience as I struggle up this learning curve.
                > Once my researching process is more efficient I won't be asking so many
                > stupid
                > questions. Hopefully the ones i am asking now aren't quite as vague as
                > they
                > were a few months ago.

                When I posted telling you how to apply filters to the Help, I _was_ trying
                to help you, not just being a smartass. Probably the biggest productivity
                enhancement I've found is my filters.


                • 5. Re: navigateToURL from XML data
                  Developer504 Level 1
                  Amy,

                  Yeah I didn't fully understand that. Where is the best place to read about using Filters in the Help? When I search I find unrelated pages like this

                  http://livedocs.adobe.com/flex/3/html/help.html?content=styles_11.html

                  ...different kind of filter I think...
                  • 6. Re: navigateToURL from XML data
                    Level 7

                    "Developer504" <webforumsuser@macromedia.com> wrote in message
                    news:g8mm6q$3p5$1@forums.macromedia.com...
                    > Amy,
                    >
                    > Yeah I didn't fully understand that. Where is the best place to read
                    > about
                    > using Filters in the Help? When I search I find unrelated pages like this
                    >
                    > http://livedocs.adobe.com/flex/3/html/help.html?content=styles_11.html

                    http://flexdiary.blogspot.com/2008/07/getting-help-in-flex-builder.html


                    • 7. Re: navigateToURL from XML data
                      Developer504 Level 1
                      Thanks Amy. Sounds like I wasn't the only one having a hard time finding an answer to this....;)

                      M.