IntelliJ IDEA 2016.1 Help

Extract Parameter in ActionScript

This section discusses the Extract Parameter refactoring in ActionScript.


// Two ways of introducing a parameter for the function // formatPrice() will be shown.public functionfoo():void{ formatPrice(0); } // The new parameter will be optional in the first // of the examples and required in the second example.public functionformatPrice(value:int):String { trace("currency: " +"$");return"$"+ value; }
// The function formatPrice() may be called as before because // the new parameter is introduced as an optional parameter.public functionfoo():void{ formatPrice(0); } // The default value for the new parameter is specified // in the function definition.public functionformatPrice(value:int,s:String = "$"):String { trace("currency: " +s);returns+ value; } // The new parameter in this example is a required parameter. // So two values must be passed to formatPrice() now.public functionfoo():void{ formatPrice(0,"$"); } // The new parameter is a required parameter because the default // value for it is not specified in the function definition.public functionformatPrice(value:int,s:String):String { trace("currency: " +s);returns+ value; }

Introducing a parameter in ActionScript

  1. In the editor, place the cursor within the expression to be replaced by a parameter.
  2. Do one of the following:
    • Press Ctrl+Alt+P.
    • Choose Refactor | Extract | Parameter in the main menu.
    • Choose Refactor | Extract | Parameter from the context menu.
  3. If more than one expression is detected for the current cursor position, the Expressions list appears. If this is the case, select the required expression. To do that, click the expression. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest, and then press Enter to select it.


  4. In the Extract Parameter dialog:
    1. Usually, IntelliJ IDEA sets a proper parameter type itself. If necessary, you can select another appropriate type from the Type list.
    2. Specify the parameter name in the Name field.
    3. The Value field, initially, contains the expression that you have selected. Normally, you don't need to change this.

      If the new parameter is going to be an optional parameter, the specified value will be used as the default parameter value in the function definition.

      If the new parameter is introduced as a required parameter, the specified value will be added to the function calls.

      For information about required and optional parameters, see the discussion of function parameters in Flex/ActionScript documentation.

    4. If you want the new parameter to be an optional parameter, select the Optional parameter check box.
    5. If more than one occurrence of the expression is found within the function body, you can choose to replace only the selected occurrence or all the found occurrences with the references to the new parameter. Use the Replace all occurrences check box to specify your intention.
    6. Click OK.


See Also

Last modified: 13 July 2016