AS3 refactoring: convert local var to instance var

this one should be pretty straigtforward but I cant seem to find it:

given that I start out like this:

public function someFunction():void {
          var someVar:String = "whatever";

lots of times I need to promote someVar to the instance level:

private var _someVar:String;
public function someFunction():void {
          _someVar = "whatever";

is there a refactor action for that? this is different from the create getters/setters action, in that I dont need those


1 comment

There's 'Extract field' refactoring. It works not exactly as you want, but pretty close to it. Shortcut is Ctrl+Alt+F on Windows or Meta+Alt+F on Mac. If you invoke it when caret is on var name - local var will be replaced with a field. If caret is on "whatever" -  local var weill remain and field will be generated. You can extract field from any initializer even without a local var, i.e. just type
public function someFunction():void {

and you'll be able to extract the field initialized with "whatever".


Please sign in to leave a comment.