all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

Dynamic drawing problem


Dynamic drawing problem jblack
8/12/2006 4:49:22 PM
flash actionscript:
I'm creating a little app that maps out the vectors of hurricanes based on data
in an XML file.
So far I've been successful with getting the app to dynamically create a movie
clip for each storm and draw a vector for each storm clip.
Going a step further, I'm trying to make it so when a user clicks on one of
the displayed storms, the storm is redrawn segment by segment with data for
each segment attached to the segment (data like wind speed, pressure, long.,
lat., time, etc.) I figured I would handle this by creating a new movie clip
for each segment and store an array for each segment within each clip.
I've set up some code that creates the movie clip, attaches the array, sets
the start point of each segment, looks ahead one data set to get the end point
for the section, and draws the line based on that.
However, when I run the app, what I get is a line that stretches diagonally
across the screen, seeming to not adhere to any of the coordinates.
Take a look. Thanks.


function showOneStorm(strmID):Void {
killAllStorms(); //removes movie clips of all storm vectors
var objStorm:Object = data.childNodes[strmID];
var stormName:String = objStorm.attributes.name;
_global.numSegments = objStorm.childNodes.length; //global var created to
feed to the killAllSegments function when going back to view all storm vectors
for (i=0; i<numSegments; i++) {
var objDataPoint:Object = objStorm.childNodes[i]; //shorten XML calls
//create vars for each segment below
var tname:String = objDataPoint.attributes.tname;
var ttime:String = objDataPoint.attributes.ttime;
var long:Number = objDataPoint.attributes.lat;
var lat:Number = objDataPoint.attributes.long;
var wind:Number = objDataPoint.attributes.wind;
var pres:Number = objDataPoint.attributes.pres;
var segmentID:String = "segment"+i; //create name for each segment movie
clip
//trace(segmentID); RETURNS CORRECT INFO
this.createEmptyMovieClip(segmentID, this.getNextHighestDepth());
this[segmentID].segmentInfo = Array(tname, ttime, long, lat, wind, pres);
//put vars into array inside each segment clip
//trace(this[segmentID].segmentInfo[0]); RETURNS CORRECT INFO
this[segmentID].lineStyle(windSize(wind), windColor(wind), 90); //set style
based on wind speed
//trace(long+"/"+lat+" startpt"); RETURNS CORRECT INFO
this[segmentID].moveTo(calcX(long), calcY(lat)); //create start point for
segment based on degree to pixel conversion
var nextpt:Number = i+1; //assign next point
var nextDataPoint:Object = objStorm.childNodes[nextpt];
var nextLong:Number = nextDataPoint.attributes.lat;
var nextLat:Number = nextDataPoint.attributes.long;
//trace(nextLong+"/"+nextLat+" endpt"); RETURNS CORRECT INFO
this[segmentID].lineTo(calcX(nextLong), calcY(nextLat)); //create line to
next point based on degree to pixel conversion
}
}
Re: Dynamic drawing problem kglad
8/12/2006 5:16:53 PM
what's calcX(), calcY(), windXize() and windColor()? are they expecting
numbers for parameters or are they able to handle the strings you are passing?
(that's a hint.)

actually, you should be getting a compiler error showing a type mismatch. are
you?
Re: Dynamic drawing problem jblack
8/13/2006 2:06:34 PM
Gotcha. I tested the typeof each variable and, sure enough, they were all
strings. I didn't realize Flash saw all values from an XML file as strings.
I defined the variables as numbers using Number() and rechecked type. Good to
go.
However, I'm still having the same problem with drawing the line using
individual clips for each segment. Results are still the same.
Thx
-Joe
Re: Dynamic drawing problem kglad
8/13/2006 2:32:40 PM
your setup is designed to use distinct movieclips for each segement. is that
something you do not want?

show the results of a few

trace(calcX(long)+" "+calcY(lat)); // and
trace(calcX(nextLong)+" "+calcY(nextLat));

statements after their arguments are defined.
Re: Dynamic drawing problem jblack
8/15/2006 1:14:22 AM
Here's the output of those trace calls.

segment0
TROPICAL DEPRESSION EIGHTEEN
22/-69.7 startpt
21.7/-71.2 endpt
segment1
TROPICAL DEPRESSION EIGHTEEN
21.7/-71.2 startpt
22/-72.2 endpt
segment2
TROPICAL DEPRESSION EIGHTEEN
22/-72.2 startpt
22.2/-72.7 endpt
segment3
TROPICAL STORM RITA
22.2/-72.7 startpt
22.9/-73.3 endpt
segment4
TROPICAL STORM RITA
22.9/-73.3 startpt
22.7/-74.3 endpt
segment5
TROPICAL STORM RITA
22.7/-74.3 startpt
23/-75.2 endpt
segment6
TROPICAL STORM RITA
23/-75.2 startpt
23.3/-76.5 endpt
segment7
TROPICAL STORM RITA
23.3/-76.5 startpt
23.3/-77.8 endpt
segment8
TROPICAL STORM RITA
23.3/-77.8 startpt
23.7/-79.5 endpt
segment9
TROPICAL STORM RITA
23.7/-79.5 startpt
23.8/-81 endpt
segment10
HURRICANE RITA
23.8/-81 startpt
23.9/-81.7 endpt
segment11
HURRICANE RITA
23.9/-81.7 startpt
24/-82.2 endpt
segment12
HURRICANE RITA
24/-82.2 startpt
24.1/-83.2 endpt
segment13
HURRICANE RITA
24.1/-83.2 startpt
24.3/-84.6 endpt
segment14
HURRICANE RITA
24.3/-84.6 startpt
24.3/-85.9 endpt
segment15
HURRICANE RITA
24.3/-85.9 startpt
24.4/-86.8 endpt
segment16
HURRICANE RITA
24.4/-86.8 startpt
24.6/-87.2 endpt
segment17
HURRICANE RITA
24.6/-87.2 startpt
24.9/-88 endpt
segment18
HURRICANE RITA
24.9/-88 startpt
25.4/-88.7 endpt
segment19
HURRICANE RITA
25.4/-88.7 startpt
25.8/-89.5 endpt
segment20
HURRICANE RITA
25.8/-89.5 startpt
26.2/-90.3 endpt
segment21
HURRICANE RITA
26.2/-90.3 startpt
26.8/-91 endpt
segment22
HURRICANE RITA
26.8/-91 startpt
27.4/-91.9 endpt
segment23
HURRICANE RITA
27.4/-91.9 startpt
28.2/-92.6 endpt
segment24
HURRICANE RITA
28.2/-92.6 startpt
29.1/-93.2 endpt
segment25
HURRICANE RITA
29.1/-93.2 startpt
29.9/-93.9 endpt
segment26
HURRICANE RITA
29.9/-93.9 startpt
31/-94.3 endpt
segment27
HURRICANE RITA
31/-94.3 startpt
32.1/-94 endpt
segment28
TROPICAL STORM RITA
32.1/-94 startpt
33/-93.9 endpt
segment29
TROPICAL DEPRESSION RITA
33/-93.9 startpt
NaN/NaN endpt
Re: Dynamic drawing problem kglad
8/15/2006 2:35:19 AM
so, the graph you would expect to see is a zig-zag mess between x=21.7 and x=23
(but that's just over 1 pixel wide so you're probably not going to notice
anything unless you scale that up).

between x=23 and x=33 you expect to see y decreasing from -75.2 to -94.3 (and
remember, this is just 10 pixels wide and less then 20 pixels high, so this
will be noticable if you look carefully (assumming y<0 is visible).

and between x=33 and x=0 you expect to see y increase from -93.9 to 0 (because
flash is going to use zero when it receives NaN data. and this is probably the
only part of the graph that you're noticing.

so, you're going to see a mess because either the data are a mess or you're
not presenting the data in an informative manner.

you might try increasing the scale of your display (by a factor of between 10
to 100, so it's more like 500 pixels wide) and don't apply the drawing api to
undefined data.
AddThis Social Bookmark Button