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.