Skip to content

Code Generation

Josh Tynjala edited this page Apr 27, 2019 · 6 revisions

The ActionScript & MXML extension for Visual Studio Code includes several code actions (also known as quick fixes) for code generation. If a code action is available at the current position in the editor, a lightbulb 💡 icon will appear in the left margin of the current line. Click this icon to open a menu to choose from the available code actions. Alternatively, you may use the Ctrl+. keyboard shortcut to open the menu.

Generate Variable

If you try to reference a variable that doesn't exist, the compiler may produce an error like this:

Access of possibly undefined property {propertyName}.

When this compiler error is detected, the Generate Local Variable code action will allow you to generate a variable inside the current function, like this:

var someValue:Object;

Similarly, the Generate Field Variable code action will allow you to generate a field (or member) variable like the one below:

public var someValue:Object;

Generate Method

If you try to call a method that doesn't exist, the compiler may produce an error like this:

Call to a possibly undefined method {methodName}.

When this compiler error is detected, the Generate Method code action will allow you to generate a method from a call like the one below:

refresh(10, true);

The generated method will include any parameters that you attempted to pass to it, with the correct types (which will be imported, if necessary):

private function refresh(param1:Number, param2:Boolean):void
{
}

Generate Getter and Setter

If your class contains a member variable, like the one below, you may use the Generate Getter and Setter code action to convert it into a getter and setter.

public var enabled:Boolean = true;

The generated functions will have the same access level (like public or private) and type as the old variable and the new private variable will be initialized to the same value:

private var _enabled:Boolean = true;

public function get enabled():Boolean
{
	return _enabled;
}

public function set enabled(value:Boolean):void
{
	_enabled = value;
}

Implement Interface

If your class implements an interface, but some of the interface's methods are missing, you may use the Implement Interface code action to generate code for the missing methods.

Further Reading

Clone this wiki locally