Skip to content

Instantly share code, notes, and snippets.

@grapefrukt
Created January 13, 2014 22:47
Show Gist options
  • Save grapefrukt/8409627 to your computer and use it in GitHub Desktop.
Save grapefrukt/8409627 to your computer and use it in GitHub Desktop.
Causes a crash on Windows XP systems once it goes above 489 rectangles
package ;
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import flash.text.TextField;
class Main extends Sprite {
var rectCount:Int = 0;
var text:TextField;
function init() {
// try toggling this line on and off
text = new TextField();
if (text != null) addChild(text);
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleEnterFrame(e:Event):Void {
rectCount += 1;
trace(rectCount);
graphics.clear();
// draws a bunch of randomly colored rectangles
for (i in 0 ... rectCount){
graphics.beginFill(Std.int(Math.random() * 0xffffff));
graphics.drawRect(Math.random() * (stage.stageWidth - 20), Math.random() * (stage.stageHeight - 20), 20, 20);
}
// pad this string with more text to make it crash sooner
if (text != null) text.text = Std.string(rectCount)
}
public function new() {
super();
addEventListener(Event.ADDED_TO_STAGE, added);
}
function added(e) {
removeEventListener(Event.ADDED_TO_STAGE, added);
init();
}
public static function main() {
Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
Lib.current.addChild(new Main());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment