Hey all,
I finally have a question to ask!
I'm working on a project that, in simplest terms, is an event visualizer.
It takes event data coming in from an XMLSocket (or a standard PHP script
pulling from a database for "replays"), creates an empty movie clip,
stores it in a simple object/array combination to aide in "timestamping",
then it uses removeMovieClip() to discard the clip when it's a minute or
so old.
Warning, I'm a complete noob when it comes to ActionScript, I have a
little bit of Javascript experience, and a good amount of PERL and Python,
so I can handle criticisms, and hopefully they can be explained in a
language I understand. :)
I have three keyframes, 1, 2 and 20, with 20 being the loop back to give
me a nearly one second tick mark, when things are not overloaded.
At 1, I instantiate an Array (_root.lines), import WDDX, and create a
custom function on the MovieClip prototype for some initial markers, along
with a few longitude/latitude-to-map-coordinates functions, and a function
for drawing curved vectors. I initialize some starting points for some
global counters on _root here, as well. Lastly, there's a map of the
globe for the scene background, and the custom function marks three
locations on the map.
At 2, I populate the initial location marks at level 1, calculate the
current date/time by instantiating Date(), and store the results on _root
for later retrieval (we'll call it _root.ratio_start). I then pull in the
data stream, currently I limit it to 2500 lines (events, really, it can be
a little more than 500 characters in XML per event). I calculate the
start point (one of the three marks) based on the data provided, then use
the latitude and longitude calculate an end point. Here's the part I'm
not sure is the most efficient:
// Increment the counter to give us a pseudo-unique number.
_root.counter++;
// make a timestamp
date_now = new Date();
// make an empty movie clip with a unique, but dynamic, name
pen = createEmptyMovieClip("vector_" + root.counter + "_mc",
root.counter+2);
// Set the line style
pen.lineStyle(2,0x00CC00);
// Store it in a simple object for later retrieval and timestamp
comparison
container = {pen: pen, timestamp: date_now);
// Pus it into the "lines" array.
_root.lines.push(container);
// Draw the vector
curvePoint(pen, x, y, x, y);
>From there, it just moves along with no more code until I get to frame 20:
// make a timestamp
date_now = new Date();
// Get the "benchmark" up until this point
_root.ratio_end = date_now;
// Calculate the ratio between the time it actually took, and one second,
for throttling purposes
_root.ratio = 1000 / (_root.ratio_end.getTime() -
_root.ratio_start.getTime());
// _root.millisecondsToMinute = 1000 * 60, get the fraction (multiple) of
1 minute.
_root.timeLimit = _root.millisecondsToMinute * _root.ratio;
temp_count = 0;
for (i = 0; i < _root.lines.length; i++) {
// Calculate the difference between the current time, and the time
this "line" was turned into a clip.
timeDiff = date_now.getTime() -
_root.lines[i].timestamp.getTime();
if (timeDiff > _root.timeLimit) {
// Keep track of how many we remove for debugging
purposes.
temp_count++;
// Remove the movie clip the only way I know how.
_root.lines[i].pen.removeMovieClip();
// remove this entry from the array.
_root.lines.splice(i,1);
}
}
// Occasionally reset the "unique counter"
if (_root.counter >= 32000) {
_root.counter = 0;
}
// Loop back to frame 2, pull more data, etc.
_root.gotoAndPlay(2);
Now, on to my actual question/comment. I've noticed that if the rate of
incoming data goes above about 2200, it fails to keep up with the
throttling, and will start to bog down. It will remove more than it's
bringing in, and eventually stablize to about a 3400 total clips in the
array at the end of each loop. However, this takes updates down to once
every 11 seconds or so, defeating the point of a once-per-second refresh
rate. If I can't get this to work more efficiently in flash, I'll likely
have to switch to another platform and language. :/
Is there something I could do that would be more efficient? I need to be
able to remove the vectors when they're about a minute old, but I couldn't
seem to find any other way than to store the clip and date object on
another, simple object, and store that in an array. A stack of sorts. I'd
rather have a way of just using a single clip for all of the vectors, but
again, I couldn't seem to find a way to remove a line I just drew. My
curvePoint() function actually uses curveTo() if that helps.
The throttling works well, but only, again, up until about a 2200
new-clips-per-second rate.
Thanks!
Michael King
CSIRT - Developer
Security Incident Response Group
Humana Inc.
E-mail: [EMAIL PROTECTED]
"STANDS: Some Theoretical Acronym Not Described Sufficiently"
The information transmitted is intended only for the person or entity to which
it is addressed and may contain CONFIDENTIAL material. If you receive this
material/information in error, please contact the sender and delete or destroy
the material/information.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com