#include "NetServices.as" if (isGatewayOpen == null) { // do this code only once isGatewayOpen = true; NetServices.setDefaultGatewayUrl("http://www.myDomain.com/flashservices/gateway"); cfServer = NetServices.createGatewayConnection(); sparkService = cfServer.getService("components.spark", this); sparkService.getSparks({SymbolName:SYM2}); } function getSparks_Result(result) { RecordCount=result.getLength()-1; var LastClose = result.items[RecordCount].closing; var x = 32; // set the dimensions of the canvas..... var Height = 30; var Width = 155; var IncrementX = (155-(2*x))/recordcount; var LastOffset = Width - x; // initialize the max and min for the record set........ var MaxClose = 0; var MinClose = 999; // set the text formating for the maximum, minimum and last closing labels formatMin = new TextFormat(); formatMin.size=9; formatMin.color=0xFF0000; formatMax = new TextFormat(); formatMax.size=9; formatMax.color=0x006600; formatLast = new TextFormat(); formatLast.size=13; formatLast.color=0x0000FF; for (i=0; i <= recordCount; i++) { MinClose=Math.min(result.items[i].closing,MinClose); MaxClose=Math.max(result.items[i].closing,MaxClose); } var MaxText = MaxClose; var MinText = MinClose; var PriceRange = MaxClose - MinClose; var Spread = Height / PriceRange; _root.createEmptyMovieClip ("Sparkline", 1); with (_root.Sparkline){ lineStyle (0, _global.Sparkline, 50); for (i=0; i <= recordCount; i++) { var y1 = result.items[i].closing - Minclose; var y2 = y1*spread; var y3 = y2+(15-y2)*1.4; var x = x + incrementX; //...check if this point is also the MaxClose or MinClose....... if (result.items[i].closing == MaxClose) { MaxDot(x,y3); var MaxDotX=x-13; var MaxDotY=y3-14; } if (result.items[i].closing == MinClose) { MinDot(x,y3); var MinDotX = x-12; var MinDotY = y3-3; } // draw the sparkline........................ if (i == 0) {moveTo (x,y3);} else {lineTo (x,y3);} } } // set the label for the minimum value..... _root.createEmptyMovieClip ("MinLabel", 600); with (_root.MinLabel){ _root.createTextField("MinLabel",600,MinDotX,MinDotY,25,15); MinLabel.text= MinText; MinLabel.setTextFormat(formatMin); MinLabel._visible = true; } // set the label for the maximum value...... _root.createEmptyMovieClip ("MaxLabel", 700); with (_root.MaxLabel){ _root.createTextField("MaxLabel",700,MaxDotX,MaxDotY,25,15); MaxLabel.text= MaxText; MaxLabel.setTextFormat(formatMax); MaxLabel._visible = true; } // set the label for the stock trading symbol...... _root.createEmptyMovieClip ("Symbol", 800); with (_root.Symbol){ _root.createTextField("Symbol",800,0,5,32,15); Symbol.html = true; Symbol.autosize = "left"; Symbol.htmltext="" + SYM2; Symbol._visible = true; } // set the label for the last closing price...... _root.createEmptyMovieClip ("LastLabel", 900); with (_root.LastLabel){ _root.createTextField("LastLabel",900,LastOffset,6,32,18); LastLabel.text=LastClose; LastLabel.setTextFormat(formatLast); LastLabel._visible = true; } } //..line above is the closing bracket for the run-once block of code..... //.....draw the green dot for the max closing value............ function MaxDot(x,y3){ _root.createEmptyMovieClip ("MaxDot", 300); with (_root.MaxDot){ lineStyle (3, 0x006600, 100); MoveTo (x,y3); LineTo (x+1,y3); } } //.....draw the red dot for the min closing value............ function MinDot(x,y3){ _root.createEmptyMovieClip ("MinDot", 400); with (_root.MinDot){ lineStyle (3, 0xFF0000, 100); MoveTo (x,y3); LineTo (x+1,y3); } }