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

Creating the Flash Ticker Component

Now that the logic to grab our quotes is in place, we need to build the actual ticker. To do this you must install Flash UI Components 2 from Macromedia and drag and drop the Ticker object into the main movie clip.

Next select your new ticker object and select the parameters tab on the properties bar. This will let us make the below customizations for the desired look and feel.

  • Speed = 15
  • Spacing = 20
  • Orientation = Horizontal
  • Scroll Direction = Decremental
  • Frame Width = 0
  • Highlight Color = #000066

You should also create a box with color #000066 behind the ticker for our background and reset the document size to 325 * 25. When done your ticker should look like the one below.

With the look down, let's remove the test code on the main movie clip, GetQuote( "MSFT" ), and replace it with the below code. This will allow us to enter as many stock quotes as we like at once.


////////////////////////////////////////////
// variables
////////////////////////////////////////////

quoteArray = new Array( "MSFT", "COKE", "SUNW", "MACR", "AAPL", "CTL", "AMD", "INTC", "DELL", "CSCO", "YHOO");
stop();

Next, let's change the instance name of our ticker to stockTicker and insert this code into the stockTicker movie clip. This code will loop through the quoteArray array and insert each quote into our ticker when it loads.


	//sets interval for timer
onClipEvent( load )
{
		//sets first set of stocks
	_root.quoteArray.sort();
	for( quotes in _root.quoteArray )
	{
		_root.GetQuote( _root.quoteArray[quotes] );
	}
	
	this.setDataAllWidth( 0 );
	this.sortItemsBy( "text", "ASC" );
}

We're almost done, but first we need to change our GetQuote_Result( result ) call back function to add the quotes into the stockTicker. The stockTicker.addItem method takes a string or TextFormat object and places it into the ticker.


	//call back function for GetQuote method
function GetQuote_Result( result )
{
	buffer = result[ 0 ] + " " + result[ 1 ] + " " +result[ 4 ];
	stockTicker.addItem( { text:buffer, textColor:0xFFFFFF, background:false, bold:true, size:10 } );
}

Test the application and watch the stocks scroll.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 4 and 5 and type the answer here:

User Comments

Title: index quotes again   
Name: kdasgupta
Date: 12/6/2008 6:13:17 PM
Comment:
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: 10/30/2008 7:52:35 PM
Comment:
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?

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

Dow - ^DJI
S&P - ^GSPC
ND - ^IXIC

full list on finance.yahoo.com.

Good luck!
Title: WSDL file for web service   
Name: Edi Hansen
Date: 7/21/2008 12:45:11 PM
Comment:
Hi,
Is there a WSDL file for this web service? I'm trying to query web service via SSIS web services task..
thanks!
Title: Index values : $SPX, $COMPQ   
Name: Liya Tansky
Date: 7/9/2008 8:33:13 PM
Comment:
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: 6/26/2008 9:59:57 AM
Comment:
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: 5/22/2008 10:59:23 AM
Comment:
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 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






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


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 1/7/2009 9:43:04 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search