Skip to main content
June 4, 2008
Answered

e.updateAfterEvent() slow down

  • June 4, 2008
  • 1 reply
  • 1068 views
Hi

I'm new to AS3 so apologies if this one has been done before but I have a problem in a scrolling routine I am trying to write.

Bacially I am trying to create a draggable moving axis on a 3D graph and everything works just fine until I start to try and drag it around really quickly.

The main code is an Event Listener atatched to the Mouse Move event and the code is triggered when a drag is taking place. As part of the processing I shuffle some arrays as the user moves along the axis and then redraw the axis and the graph components followed by an e.updateafterevent() to update the stage.

As far as I can tell my array shuffling routines work just fine but the screen update gets slower and slower until it almost stops after a period of fast dragging.

I have had a look around and there seems to be some doubt about updateafterevent working properly when you are doing a lot of processing - my question is - should I be using it and if not is there a decent alternative to cause the stage to update ?

Thanks
This topic has been closed for replies.
Correct answer Andrei1-bKoviI
A brief look at your code suggests that you draw a new object every time mouse moves (your function mMove - you call minner()). Well, it looks this is the main problem. First of all there is no clearing of the previous drawing. You should invoke clear() method before you redraw. What, I believe, it does now is drawing all these gazillions times 2 objects that overwhelm the memory.

Also, I would look into code optimization. For instance, I would declare variables that are set repeatedly outside the functions and just set the values inside the functions - it will improve performance.

For instance, your function is:

function minner():void {

var fsquarex:Number = mwidth*squares/totalis;
//etc.

I would do:

var fsquarex:Number; //outside

unction minner():void {

fsquarex = mwidth*squares/totalis;
//etc.

Or:

Instead of

if (isstart > (totalis + 1 - squares)) {
isstart = totalis + 1 - squares;
}

something like

someVar = totalis + 1 - squares
if (isstart > someVar) {
isstart = someVar;
}

Secondly, can I ask you why don't you use native startDrag instead of writing your own functionality?

1 reply

June 4, 2008
This is the offending code - if you try dragging the white rectangle around for a while it will get slower and slower and more stuttering - any suggestions gratefully received.

ignore all the other variables as I have set them to constants in my example - they are necessary in my program.
Andrei1-bKoviICorrect answer
Inspiring
June 4, 2008
A brief look at your code suggests that you draw a new object every time mouse moves (your function mMove - you call minner()). Well, it looks this is the main problem. First of all there is no clearing of the previous drawing. You should invoke clear() method before you redraw. What, I believe, it does now is drawing all these gazillions times 2 objects that overwhelm the memory.

Also, I would look into code optimization. For instance, I would declare variables that are set repeatedly outside the functions and just set the values inside the functions - it will improve performance.

For instance, your function is:

function minner():void {

var fsquarex:Number = mwidth*squares/totalis;
//etc.

I would do:

var fsquarex:Number; //outside

unction minner():void {

fsquarex = mwidth*squares/totalis;
//etc.

Or:

Instead of

if (isstart > (totalis + 1 - squares)) {
isstart = totalis + 1 - squares;
}

something like

someVar = totalis + 1 - squares
if (isstart > someVar) {
isstart = someVar;
}

Secondly, can I ask you why don't you use native startDrag instead of writing your own functionality?
June 4, 2008
Hi Andrei1

That is fantastic - putting in the clear makes it work just fine.

Its cost me a couple of days at least trying to find out why it wasnt working - I was beginining to think it was me so I am very very grateful.

Thanks also for the suggestions re performance - my plan is to do a tidy up once I've got the basics going.

I copied the starting code from another bit of code which used the Mouse events to do the drag but I will have a look at your sugegstion to see if it could improve the code.

Thanks once again and I am very very grateful.

Chris