Re: [Flashcoders] actionscript/flash performance

2007-03-27 Thread [p e r c e p t i c o n]

if you use date in this context MovieClip.prototype.age = new Date(); and
you want incremental values, you should pass in some parameters like hour,
minutes, seconds and milliseconds...check documentation on this...


As to the XML data being asynchronous, so you mean I don't actually have
to use gotoAndPlay()?  I can just start off with a stop(); and set up the
event code?


that's correct...you certainly want to set up event handlers...


On 3/27/07, Michael King <[EMAIL PROTECTED]> wrote:


Hello,

Thanks for the response.  So by using prototype, I could set the date on
it, and at the very least get rid of the simple object I'm creating for
the array, and just go directly to the array?

Something like:

MovieClip.prototype.age = new Date();

Or is there something else I need to do to make sure it has an increasing
date with each loop?

As to the XML data being asynchronous, so you mean I don't actually have
to use gotoAndPlay()?  I can just start off with a stop(); and set up the
event code?

I did it the way it is now because I need to use the code with two
possible ways - an XML packet from a socket, or an XML request from a PHP
script hitting a MySQL backend (this would facilitate "replaying" events,
whereas the socket would be the live-events-as-they-happen version).

Again, thanks for the response, I'm hoping I can keep this in Flash, as it
presents a wonderful way to have multiple clients viewing the same data,
with a much smaller effect on the server than other methods -- I also
don't know C/C++ very well. :)


Thanks,

Michael King
CSIRT - Developer
Security Incident Response Group
Humana Inc.
E-mail: [EMAIL PROTECTED]
"STANDS: Some Theoretical Acronym Not Described Sufficiently"



"[p e r c e p t i c o n]" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
03/27/2007 01:43 PM
Please respond to
flashcoders@chattyfig.figleaf.com


To
flashcoders@chattyfig.figleaf.com
cc

Subject
Re: [Flashcoders] actionscript/flash performance






Hi Michael,
one thing that stands out right away is the use of prototype...if i'm not
mistaken, this will make these variables available to all movie
clips...even
ones that don't use the markers you're speaking of...the other thing is
that
loading of xml data is asynchronous, so you just burning cycles by looping
this way...i would use set interval to manage the removal of the clips
...it's far more efficient...

just my .02




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.
___
Flashcoders@chattyfig.figleaf.com
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


___
Flashcoders@chattyfig.figleaf.com
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


RE: [Flashcoders] actionscript/flash performance

2007-03-27 Thread Joe Wheeler
2200 clips is a lot - I'm not surprised you're running into problems. There
is quite a large overhead with each movieclip you instantiate (anyone know
how many kb an individual mc weighs?).

I think your idea of using a single clip is a much better idea. You'd have
to clear() and redraw from scratch each time there's an update but with a
clever bit of animation you could probably make that manageable (if you only
plotted 100 points per frame at 31fps, you should be able to achieve roughly
3100 points/second ). I'd create a flyweight class to abstract the shapes
you have been drawing into the pen movieclips - essentially it would just
hold the point data (call it PenData?). I'd then create and update loop
which runs through the PenData instances and draws them at a rate of 100 per
frame into your single movieclip. Next time there's an update, clear the
movieclip and start again...

You are pushing the limits but I think it's worth trying. 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael King
Sent: 27 March 2007 17:57
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] actionscript/flash performance

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 dow

Re: [Flashcoders] actionscript/flash performance

2007-03-27 Thread Michael King
Hello,

Thanks for the response.  So by using prototype, I could set the date on 
it, and at the very least get rid of the simple object I'm creating for 
the array, and just go directly to the array?

Something like:

MovieClip.prototype.age = new Date(); 

Or is there something else I need to do to make sure it has an increasing 
date with each loop?

As to the XML data being asynchronous, so you mean I don't actually have 
to use gotoAndPlay()?  I can just start off with a stop(); and set up the 
event code?

I did it the way it is now because I need to use the code with two 
possible ways - an XML packet from a socket, or an XML request from a PHP 
script hitting a MySQL backend (this would facilitate "replaying" events, 
whereas the socket would be the live-events-as-they-happen version).

Again, thanks for the response, I'm hoping I can keep this in Flash, as it 
presents a wonderful way to have multiple clients viewing the same data, 
with a much smaller effect on the server than other methods -- I also 
don't know C/C++ very well. :)


Thanks,

Michael King
CSIRT - Developer
Security Incident Response Group
Humana Inc.
E-mail: [EMAIL PROTECTED]
"STANDS: Some Theoretical Acronym Not Described Sufficiently"



"[p e r c e p t i c o n]" <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
03/27/2007 01:43 PM
Please respond to
flashcoders@chattyfig.figleaf.com


To
flashcoders@chattyfig.figleaf.com
cc

Subject
Re: [Flashcoders] actionscript/flash performance






Hi Michael,
one thing that stands out right away is the use of prototype...if i'm not
mistaken, this will make these variables available to all movie 
clips...even
ones that don't use the markers you're speaking of...the other thing is 
that
loading of xml data is asynchronous, so you just burning cycles by looping
this way...i would use set interval to manage the removal of the clips
...it's far more efficient...

just my .02




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.
___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] actionscript/flash performance

2007-03-27 Thread [p e r c e p t i c o n]

Hi Michael,
one thing that stands out right away is the use of prototype...if i'm not
mistaken, this will make these variables available to all movie clips...even
ones that don't use the markers you're speaking of...the other thing is that
loading of xml data is asynchronous, so you just burning cycles by looping
this way...i would use set interval to manage the removal of the clips
...it's far more efficient...

just my .02

On 3/27/07, Michael King <[EMAIL PROTECTED]> wrote:


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