Building a Yahoo stock quote ticker
page 4 of 7
by Jason Perry
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 51794/ 64

Connecting Flash to the Web Service

In order for your flash application to communicate with the web service, you need to install the Flash remoting package from Macromedia. Also, it's very important that you place the flashgateway.dll file (included with Flash remoting for ASP.Net) into your web server's bin folder and make the below changes to your web.config file. These changes will allow Flash to determine what calls are meant for your flash application and call the proper web service. You'll also need to create a blank file named gateway.aspx and place it on your web server. I placed this file in the same location as my web service, but it's up to you.

     <add name="GatewayController" type="FlashGateway.Controller.GatewayController,flashgateway" />

To establish the connection to our web service we must include the file. This file, included with Flash remoting, will implement the classes necessary to create a wrapper to our service.

Then we can create a connection to the web server gateway. In your code you will replace the //gateway.aspx and //YahooQuoteWebService.asmx?wsdl with the address of your web server and path to the gateway.aspx and YahooQuoteWebService.asmx files.

#include ""

// Inits Web Service

	//creates connection to ASP.Net web service
	//should never ever  run more than once!!
if( init == null )
		//insures this code block is only run once
	init = true;
		//sets the gatway will always be this
	gatewayConnnection = NetServices.createGatewayConnection();

		//gets the Yahoo quote service and sets instance
		//uses WSDL to create proxy dll file
	YahooQuoteWebService = gatewayConnnection.getService("http:////YahooQuoteWebService.asmx?wsdl", this);


We need to develop call back functions and wrappers for our web service methods. When we call the GetQuote( string ) method on our web service, Flash will connect to the service and send the response back to _Result( result ) or _Status( error ). If a error occurs while trying to connect to the service, the _Status( error ) call back will be used, otherwise _Result( result ) will be called with the data from the service in the result object. Our result object is an array of strings so we can access this array like we would any Flash array object. NOTE: For a full list of result objects supported by Flash, see the Flash Remoting documentation.

// Call Back Function Wrappers

	//gets quote data from web service
function GetQuote( symbol )
	YahooQuoteWebService.GetQuote( symbol );	
	trace( "getting " + symbol + " from yahoo quote web service" );

// Call Back Functions

	//call back function for GetQuote method
function GetQuote_Result( result )
	buffer = result[ 0 ] + " " + result[ 1 ] + " " + result[ 4 ];
	trace( buffer );

	//call back function tracks status of GetQuote method
function GetQuote_Status( error )
	trace( error.details );

After building our call back functions we can test our application by inserting the below lines of code at into our Action Script. This code will get the symbol, current value, and change data for Microsoft and display it in your trace window.

GetQuote( "MSFT" );

View Entire Article

User Comments

Title: Nasdaq, S&P500 fix   
Name: John Dalnes
Date: 2009-07-15 1:11:34 PM
I found this works for Nasdaq and other indexes
if (symbol.IndexOf("^") == 0)
url = "" + symbol + "&d=t&f=sl1d1t1c1ohgvj1pp2wern";


url = "" + symbol + "&d=t&f=sl1d1t1c1ohgvj1pp2wern";
Title: index quotes   
Name: tilistor
Date: 2009-03-23 11:21:46 AM
Dude try like this from your code:

Replace ^ with %5E

Title: webservice   
Name: stock market
Date: 2009-01-27 7:30:08 AM
pls give the code how to access webservice in the aspx page in
Title: Index quotes   
Name: Steve
Date: 2009-01-08 9:41:40 AM
Did anyone solve this problem of the ^ being translated to the hex code "%5E"? If you enter the ^ mmaulaly in the browser within a URL it works fine. It doesn't work from within the my VB code webclient.
Title: index quotes again   
Name: kdasgupta
Date: 2008-12-06 6:13:17 PM
Looks like Yahoo Quote stopped handling URL decoding of special characters. So, when I enter ^DJI for DOW, it is encoded as "%5EDJI". At Yahoo end, the special characters are not decoded to its corresponding character value, hence Yahoo quote service does not find any price data for the encoded symbol. "INDU" in place of ^DJI works fine.
Can anybode suggest fix for this problem? Thanks.
Title: index quotes again   
Name: Li
Date: 2008-10-30 7:52:35 PM
I have the same problem getting S&P and Nasdaq. When I put in ^GSPC and ^IXIC, they are not working. But, if I put in "INDU", it works for Dow. Can anybody help?

Title: Index quotes   
Name: Greg K.
Date: 2008-10-13 9:17:20 AM
To get an index quote, use ^ instead of $.

Dow - ^DJI

full list on

Good luck!
Title: WSDL file for web service   
Name: Edi Hansen
Date: 2008-07-21 12:45:11 PM
Is there a WSDL file for this web service? I'm trying to query web service via SSIS web services task..
Title: Index values : $SPX, $COMPQ   
Name: Liya Tansky
Date: 2008-07-09 8:33:13 PM
Hi, I'm trying to get values of indexes like $SPX and $COMPQ,
Your example works great for stocks, but returns empty data for $SPX. What should I change in the url in order to get to its values?

Thanks in advance
Title: Web service   
Name: Ces M
Date: 2008-06-26 9:59:57 AM
The web service seems to work fine. It pulls data from Yahoo. My question is do I still need a flash remote package which is almost $1000? Or can we just use simple actionscript to get xml file from the web service?
Title: No longer works   
Name: Ben Poole
Date: 2008-05-22 10:59:23 AM
it appears that Yahoo! has moved this web service, or changed the link. The pages I have used this code on are now broken, and I can't browse directly to the web service anymore.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-15 10:17:37 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search