tags:

views:

87

answers:

2

I am trying to retrieve a stock quote from Yahoo! finance using Flex. I currently have it set so that it will pull the quote like I want, but it opens it in a new file. However, I want to store the CSV data in a variable so that I can use it in my program.

How do I do this?

Here is the code that I am using right now:

navigateToURL(new URLRequest("http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1"),"_self");
+3  A: 

navigateToURL will open a URL from within a Flex application.

Take a look at HTTPService at http://livedocs.adobe.com/flex/3/html/data_access_2.html . It should give you back the results of the HTTP call; which you can than parse and traverse at your leisure.

www.Flextras.com
+2  A: 
<mx:HTTPService id="userRequest" url="http://download.finance.yahoo.com
    /d/quotes.csv?s=aapl&f=l1" useProxy="false" method="POST" resultFormat="object"
 result="{resultEvent(event)}">

public function init() {
      userRequest.send()      
}

public function resultEvent(event:ResultEvent) {

        trace(event.result);

 }

On your result event, trace your data.

Vinothbabu
Now I ran into a security problem :(
samoz
Whats that, what error you get? Are you able to trace?
Vinothbabu
It's because of crossdomain.xml on yahoo, for some reason I cannot access it. It says something along the lines of "Denied access because of policy file" It seems like the technique is to pull the data from the website using something like PHP to avoid Flash security problems and then read that data locally from Flex. Does that seem right?
samoz
No, you can read the data without doing anything you have commented. Have you placed crossdomain.xml in your root path. http://search.yahooapis.com/crossdomain.xmlYahoo's crossdomain.xml should allow you retrieve data from their services.
Vinothbabu