Press "Enter" to skip to content

AS3 Component Parameters always NULL or empty? Here’s an even better fix.

In a previous post I explained how to make a component by adding this to it’s class

public var myNewComponentParam:String = '';

And then explained that the flash compiler can’t access that component property’s values until AFTER the constructor function has run. Originally I proposed this solution, which waits for the stage to be built and for the playhead to hit the first frame before attempting to grab any component properties.

public function myConstructor() {
	this.addEventListener(Event.EXIT_FRAME, afterEverythingElse,
	false, 0, true);
public function afterEverythingElse() {
	this.removeEventListener(Event.EXIT_FRAME, afterEverythingElse);

A commenter named Charis Bournazos pointed out that this method means we’re getting component properties at the exact moment that the first frame is displayed, and if you’re doing something visual with that property, you often see a jump. Here’s what he (she?) suggested as the fix.

public function myConstructor() {
	this.addFrameScript(0, rightBeforeDrawingTheFirstFrame)
public function rightBeforeDrawingTheFirstFrame() {

As you can see, this calls the rightBeforeDrawingTheFirstFrame() function before first frame, which apparently (I haven’t verified) means no more jump.

Thanks Charis!


  1. Download Templates Download Templates December 28, 2011

    Excellent post. I was checking constantly this weblog and I am impressed! Very helpful information specifically the ultimate phase :) I take care of such information much. I was seeking this certain information for a long time. Thanks and good luck.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: