View Full Version : Extreme slowdown. Is this a Flash bug?

Sam Goldmann
10-21-2010, 07:27 AM
I have a setup where I'm handling the enterFrame event of my application. In the handler, I draw two rectangles (one fullscreen, one small orbiting one) using the graphics member of an mx.containers.Canvas object.

After a few minutes of execution, the app slows down substantially. Given enough time, it will come to a lowly crawl. I get the same result regardless of release/debug build on chrome, IE, and Firefox using Flash Player 10.1. Presented below is the Flex project in question:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="..."
frameRate="40" width="600" height="400"
import flash.utils.getTimer;
private var time:int = 0;
protected function application1_enterFrameHandler(event:Event):void
var time:uint = flash.utils.getTimer();

// Draw fullscreen rect.
myCanvas.graphics.drawRect(x, y, width, height);

// Draw orbiting square.
var pos:int = (int)(time * 0.1);
var x0:Number = pos % myCanvas.width;
var y0:Number = myCanvas.height * 0.5;
myCanvas.graphics.drawRect(x0 - 20, y0 - 20, 40, 40);
<mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas"/>

I had to replace namespace URIs (with "...") since i can't post URLs yet.

10-21-2010, 02:01 PM
Why are you drawing the same fullscreen rect on every frame? 40 times every second?

Why are you using the draw api to animate the orbiting square ?

Draw both once. Draw the orbiting square on a sprite. Animate the sprite.

It's not a flash bug - it's your curious approach.

10-21-2010, 02:03 PM
you are accumulating drawings on top of each other. Use:
before drawing again.

Sam Goldmann
10-21-2010, 06:14 PM
Thank you so much ASWC! I'm so naive :)