Add a stock ticker to your script with this easy to use class.
This is the code in the Ticker.as class
package com.atJascha{
import flash.text.*;
import flash.net.*;
import flash.display.*;
import flash.utils.*;
import flash.events.*;
public class Ticker extends Sprite {
private var _updateTimer:Timer;
private var _dataPath:String;
private var _stockSymbol:String;
private var _stockInfo:String;
private var _parseArray:Array;
private var _dataField:TextField;
public function Ticker(dataPath:String, stockSymbol:String) {
_dataPath=dataPath;
_stockSymbol=stockSymbol;
_stockInfo="s="+_stockSymbol+"&f=noghl1p2vs"; // to see what these symbols mean click here
_updateTimer = new Timer(10000);
_updateTimer.addEventListener(TimerEvent.TIMER, getQuote);
_updateTimer.start();
var e:Event;
getQuote(e);
buildStock();
}
private function getQuote(e:Event):void {
var variables:URLVariables = new URLVariables();
variables.info=_stockInfo;
var urlRequest:URLRequest=new URLRequest(_dataPath);
urlRequest.method=URLRequestMethod.POST;
urlRequest.data=variables;
var stockLoader:URLLoader = new URLLoader();
stockLoader.load(urlRequest);
stockLoader.addEventListener(Event.COMPLETE, addStock);
stockLoader.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler);
}
private function IOErrorHandler(e:Event):void {
getQuote(e);
}
private function addStock(e:Event):void {
var array:Array=e.target.data.split("\n");
array.pop();
var parseArray:Array = new Array();
for (var i:int=0; i<array.length; i++) {
var s:String=array[i].substr(0,array[i].indexOf("\n")-1);
var nArray:Array=s.split(",");
for (var con:int = 0; con<nArray.length; con++) {
parseArray.push(nArray[con]);
}
}
updateQuote(parseArray);
}
private function updateQuote(parseArray:Array):void
{
var textFormat:TextFormat = new TextFormat;
textFormat.size = 20;
textFormat.font = "Tahoma";
_dataField.text = parseArray[0] + "\n";
_dataField.text += "Open: " + parseArray[1] + "\n";
_dataField.text += "Day's Low: " + parseArray[2] + "\n";
_dataField.text += "Day's High: " + parseArray[3] + "\n";
_dataField.text += "Last Trade Prce: " + parseArray[4] + "\n";
_dataField.text += "Change: " + parseArray[5] + "\n";
_dataField.text += "Volume: " + parseArray[6] + "\n";
_dataField.text += "Symbol: " + parseArray[7] + "\n";
_dataField.setTextFormat(textFormat);
}
/* STOCK ARRAY ORDER ...
* [0]n = name
* [1]o = open
* [2]g = day low
* [3]h = day high
* [4]l1 = last trade price
* [5]p2 = change in percent
* [6]v = volume
* [7]s = symbol
*
*/
private function buildStock():void
{
var bg:Sprite = new Sprite();
bg.graphics.beginFill(0xEEEEEE);
bg.graphics.drawRect(0,0,300,200);
bg.graphics.endFill();
addChild(bg);
_dataField = new TextField();
_dataField.multiline = true;
_dataField.autoSize = TextFieldAutoSize.LEFT;
bg.addChild(_dataField);
}
}
}
You invoke it in your document class with this code:
import com.atJascha.*;
var ticker:Ticker = new Ticker("getDow.php", "GE"); // parameters are path to the php file and then your stock symbol.
addChild(ticker);
The php is even simpler:
<?php
$stock = require("http://download.finance.yahoo.com/d/quotes.csv?". $_POST['info']);
echo $stock;
?>
that’s that!
It could use some formatting and love, but ultimately you get your info.
Download the source code here

Stumble it!

Good sample. Thanks, I am just finding the way to get the stock market data.
But i got the error >> Error opening URL
>> IOErrorEvent type=”ioError” bubbles=false cancelable=false eventPhase=2 text=”Error #2032: Stream Error.
It seems like the php problem.
Do you have any idea how to setup the php file?
Thanks
HI, i was testing like that: Flash swf file on desktop and php file on the server.
As long as you have the full URL to your .php file you should be all right… for example var ticker:Ticker = new Ticker(“http://yourdomain.com/getDow.php”, “GE”);