?
Solved

drawpath refresh with new data from xml

Posted on 2011-09-21
1
Medium Priority
?
272 Views
Last Modified: 2012-05-12
hi, I'm to using the XML data to draw a chart.. the chart has 40 variations and the data is read in from the XML which works okay... the drawpath work okay... however I'm stuck when trying to redraw the path with the next set of data..

the first lot of data come in and draws the chart fine

but when the second lot of data loads im finding it dificult to refresh the chart sprites.... ive added the code below first the xML.. then the AS

again, i'd appreciate any advise and help


 conPlotData.xml
var XMLdataRequest:URLRequest = new URLRequest("conPlotData.xml");
// create a loader
var XMLdataLoaded:URLLoader = new URLLoader();
// new variable that is XML data
var XMLdata:XML;


// define the line style


 
var plot_commands:Vector.<int> = new Vector.<int>(); // establish a new Vector object for the commands parameter
plot_commands.push(1);// 1 moveTo command followed by 3 lineTo commands// use  the Vector array push() method to add moveTo() and lineTo() values

var plot_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object for the data parameter
var bondFloor_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object 
var parity_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object 

var cbSprite:Sprite = new Sprite();
var bfSprite:Sprite = new Sprite();
var paritySprite:Sprite = new Sprite();

var spriteHolder:Sprite = new Sprite();

cbSprite.graphics.lineStyle(6,0xFFFFFF);
bfSprite.graphics.lineStyle(6,0xFFFF00);
paritySprite.graphics.lineStyle(6,0x00FFFF);
 
 
var chart_width:Number = 1800;
var dataPoints:Number = chart_width/12
var dataPoints2:Number = dataPoints;
var dataPointScale:Number = 600;
var dataPointScale2:Number = new Number;


var bPrice:Number = new Number;
var bPriceX:Number = new Number;

var bondFloor:Number = new Number;
var bondFloorX:Number = new Number;

var parity:Number = new Number;
var parityX:Number = new Number;

var scaleYDiv:Number = new Number;//number of divisions on Y scale
var bpTop:Number = new Number;//bond price high (could be other pricing)
var bpLow:Number = new Number;//bond price low (could be other pricing)
var pxTop:Number = new Number;//pixel position top (should be zero)
var pxLow:Number = new Number;//pixel position low (dependent on height of chart)
var pixelX:Number = new Number;//the number required to multiply the bpTop - bPrice
var a1X:Number = new Number;//the number required to multiply the bpTop - bPrice
var a2X:Number = new Number;//the number required to multiply the bpTop - bPrice


scaleYDiv = 10;
bpTop = 140; // later date we need to add this from xml and give it rounding up
bpLow = 70; //later date we need to add this from xml and give it rounding down
pxTop = 600;
pxLow = 0; //chart is 600 heigh but need to add this dynamically
pixelX = (pxTop-pxLow)/(bpTop-bpLow)
trace(pixelX);




//trace(Math.round(dataPoints));
function XMLdataLoadedFunction(event:Event):void
	{
		
		XMLdata = new XML(XMLdataLoaded.data);
		
		for(var i1:Number=0; i1<=11;i1++)
			{
				//use the Vector array push() method to add a set of coordinate pairs

				plot_commands.push(2);
				
			}
			
			
			dataPointScale2 = 0;
			var ii:Number=1;
			
				var CBTimer:Timer = new Timer(100, 40);
				CBTimer.addEventListener(TimerEvent.TIMER, CBtimerListener);
				function CBtimerListener (e:TimerEvent):void
				{
			 
						for each(var a:XML in XMLdata.xyPlot.(@ImpVol==ii))
							
							{
								
								//trace (a.name() + " : " + a.toXMLString());
								plot_coord.push(Math.round(dataPointScale2));
								
								bondFloor_coord.push(Math.round(dataPointScale2));
								
								parity_coord.push(Math.round(dataPointScale2));
								
								
								trace ("result = " + a.@CBPrice + "     ii = " + ii);
								
								bPrice  = (a.@CBPrice);
								bPriceX = pixelX*(bpTop - bPrice)
								plot_coord.push((bPriceX));		
								
								bondFloor  = (a.@BondFloor);
								bondFloorX = pixelX*(bpTop - bondFloor)							
								bondFloor_coord.push((bondFloorX));
								
								parity  = (a.@Parity);
								parityX = pixelX*(bpTop - parity)							
								parity_coord.push((parityX));
								
								
								dataPointScale2 = dataPointScale2 + dataPoints
								
							}
				
				ii = ii + 1	
				trace("Timer is Triggered+++++++++");	
				
				cbSprite.graphics.drawPath(plot_commands, plot_coord);							
				bfSprite.graphics.drawPath(plot_commands, bondFloor_coord);
				paritySprite.graphics.drawPath(plot_commands, parity_coord);
				
				spriteHolder.addChild(cbSprite)				
				spriteHolder.addChild(bfSprite);
				spriteHolder.addChild(paritySprite);
				
				addChild(spriteHolder)
			    
				
				
												
				}
			
				CBTimer.start();
						
	}
trace(bondFloor_coord)

//add event listener then run function
XMLdataLoaded.addEventListener(Event.COMPLETE, XMLdataLoadedFunction);
XMLdataLoaded.load(XMLdataRequest);

Open in new window

var XMLdataRequest:URLRequest = new URLRequest("conPlotData.xml");
// create a loader
var XMLdataLoaded:URLLoader = new URLLoader();
// new variable that is XML data
var XMLdata:XML;


// define the line style


 
var plot_commands:Vector.<int> = new Vector.<int>(); // establish a new Vector object for the commands parameter
plot_commands.push(1);// 1 moveTo command followed by 3 lineTo commands// use  the Vector array push() method to add moveTo() and lineTo() values

var plot_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object for the data parameter
var bondFloor_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object 
var parity_coord:Vector.<Number> = new Vector.<Number>();// establish a new Vector object 

var cbSprite:Sprite = new Sprite();
var bfSprite:Sprite = new Sprite();
var paritySprite:Sprite = new Sprite();

var spriteHolder:Sprite = new Sprite();

cbSprite.graphics.lineStyle(6,0xFFFFFF);
bfSprite.graphics.lineStyle(6,0xFFFF00);
paritySprite.graphics.lineStyle(6,0x00FFFF);
 
 
var chart_width:Number = 1800;
var dataPoints:Number = chart_width/12
var dataPoints2:Number = dataPoints;
var dataPointScale:Number = 600;
var dataPointScale2:Number = new Number;


var bPrice:Number = new Number;
var bPriceX:Number = new Number;

var bondFloor:Number = new Number;
var bondFloorX:Number = new Number;

var parity:Number = new Number;
var parityX:Number = new Number;

var scaleYDiv:Number = new Number;//number of divisions on Y scale
var bpTop:Number = new Number;//bond price high (could be other pricing)
var bpLow:Number = new Number;//bond price low (could be other pricing)
var pxTop:Number = new Number;//pixel position top (should be zero)
var pxLow:Number = new Number;//pixel position low (dependent on height of chart)
var pixelX:Number = new Number;//the number required to multiply the bpTop - bPrice
var a1X:Number = new Number;//the number required to multiply the bpTop - bPrice
var a2X:Number = new Number;//the number required to multiply the bpTop - bPrice


scaleYDiv = 10;
bpTop = 140; // later date we need to add this from xml and give it rounding up
bpLow = 70; //later date we need to add this from xml and give it rounding down
pxTop = 600;
pxLow = 0; //chart is 600 heigh but need to add this dynamically
pixelX = (pxTop-pxLow)/(bpTop-bpLow)
trace(pixelX);




//trace(Math.round(dataPoints));
function XMLdataLoadedFunction(event:Event):void
	{
		
		XMLdata = new XML(XMLdataLoaded.data);
		
		for(var i1:Number=0; i1<=11;i1++)
			{
				//use the Vector array push() method to add a set of coordinate pairs

				plot_commands.push(2);
				
			}
			
			
			dataPointScale2 = 0;
			var ii:Number=1;//can change this number up to 40 but need to step through 1 to 40
			
				var CBTimer:Timer = new Timer(100, 40);
				CBTimer.addEventListener(TimerEvent.TIMER, CBtimerListener);
				function CBtimerListener (e:TimerEvent):void
				{
			 
						for each(var a:XML in XMLdata.xyPlot.(@ImpVol==ii))
							
							{
								
								//trace (a.name() + " : " + a.toXMLString());
								plot_coord.push(Math.round(dataPointScale2));
								
								bondFloor_coord.push(Math.round(dataPointScale2));
								
								parity_coord.push(Math.round(dataPointScale2));
								
								
								trace ("result = " + a.@CBPrice + "     ii = " + ii);
								
								bPrice  = (a.@CBPrice);
								bPriceX = pixelX*(bpTop - bPrice)
								plot_coord.push((bPriceX));		
								
								bondFloor  = (a.@BondFloor);
								bondFloorX = pixelX*(bpTop - bondFloor)							
								bondFloor_coord.push((bondFloorX));
								
								parity  = (a.@Parity);
								parityX = pixelX*(bpTop - parity)							
								parity_coord.push((parityX));
								
								
								dataPointScale2 = dataPointScale2 + dataPoints
								
							}
				
				ii = ii + 1	
				trace("Timer is Triggered+++++++++");	
				
				cbSprite.graphics.drawPath(plot_commands, plot_coord);							
				bfSprite.graphics.drawPath(plot_commands, bondFloor_coord);
				paritySprite.graphics.drawPath(plot_commands, parity_coord);
				
				spriteHolder.addChild(cbSprite)				
				spriteHolder.addChild(bfSprite);
				spriteHolder.addChild(paritySprite);
				
				addChild(spriteHolder)
			    
				
				
												
				}
			
				CBTimer.start();
						
	}
trace(bondFloor_coord)

//add event listener then run function
XMLdataLoaded.addEventListener(Event.COMPLETE, XMLdataLoadedFunction);
XMLdataLoaded.load(XMLdataRequest);

Open in new window

0
Comment
Question by:nth1971
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 2000 total points
ID: 36580318
A couple of thoughts for you to try out:

1. you're re-using the same Sprite to draw your items on, but you're still using addChild() to re-add it to the displayList. You should consider using removeChild() to remove the old version of the Sprite before adding it. You'll get an error if you remove something that isn't there, so you should run a check first. If it hasn't been added, it's parent should be null. So if (spriteHolder.parent) removeChild(spriteHolder);

2. You're using the sprite's graphics property to draw graphics to the Sprite, but you should remember to use the graphics.clear() method to get rid of your old data (assuming you're not just trying to overlay the new data on the old).

3. you're making cbSprite and bfSprite part of the application scope by declaring those variables outside of your load() handler. Consider removing them from the application scope and just scoping them inside the handler. You don't really need to keep any references to them, heck you don't even need a reference to spriteHolder if you want to get right down to it. So up near the top of your load handler, just declare your sprites there: var cbSprite:Sprite = new Sprite() etc...

These are shots in the dark after scanning through your code.Try these out and if nothing pans out, let us know!

T
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question