private statement

 class someClassName{
 private var name;
 private function name() {
 // your statements here 
 } 
}

Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.

Specifies that a variable or function is available only to the class that declares or defines it or to subclasses of that class. By default, a variable or function is available to any caller. Use this keyword if you want to restrict access to a variable or function.

You can use this keyword only in class definitions, not in interface definitions.

Availability: ActionScript 2.0; Flash Lite 2.0

Parameters

name:String - The name of the variable or function that you want to specify as private.

Example

The following example demonstrates how you can hide certain properties within a class using the private keyword. Create a new AS file called Login.as.

class Login { 
 private var loginUserName:String; 
 private var loginPassword:String; 
 public function Login(param_username:String, param_password:String) { 
 this.loginUserName = param_username; 
 this.loginPassword = param_password; 
 } 
 public function get username():String { 
 return this.loginUserName; 
 } 
 public function set username(param_username:String):Void { 
 this.loginUserName = param_username; 
 } 
 public function set password(param_password:String):Void { 
 this.loginPassword = param_password; 
 } 
}

In the same directory as Login.as, create a new FLA or AS document. Enter the following ActionScript in Frame 1 of the Timeline.

import Login; 
var gus:Login = new Login("Gus", "Smith"); 
trace(gus.username); // output: Gus 
trace(gus.password); // output: undefined 
trace(gus.loginPassword); // error

Because loginPassword is a private variable, you cannot access it from outside the Login.as class file. Attempts to access the private variable generate an error message.

See also

public statement