03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ActionScript</strong> <strong>2.0</strong> code that uses the Circle class<br />

var myCircle:Circle = new Circle(5);<br />

trace(myCircle.getArea());<br />

trace(myCircle.getDiameter());<br />

myCircle.setRadius("10");<br />

trace(myCircle.radius);<br />

trace(myCircle.getArea());<br />

trace(myCircle.getDiameter());<br />

See also<br />

class statement<br />

private statement<br />

class someClassName{<br />

private var name;<br />

private function name() {<br />

// your statements here<br />

}<br />

}<br />

Specifies that a variable or function is available only to the class that declares or defines it or to<br />

subclasses of that class. By default, a variable or function is available to any caller. Use this<br />

keyword if you want to restrict access to a variable or function. This keyword is intended as a<br />

software development aid to facilitate good coding practices such as encapsulation, <strong>and</strong> not as<br />

a security mechanism to obfuscate or secure sensitive data. It does not necessarily prevent<br />

access to a variable at runtime.<br />

You can use this keyword only in class definitions, not in interface definitions.<br />

Availability: <strong>ActionScript</strong> <strong>2.0</strong>; Flash Player 6<br />

Parameters<br />

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

Example<br />

The following example demonstrates how to restrict access to variables or functions by using<br />

the private keyword. Create a new AS file called Alpha.as:<br />

class Alpha {<br />

private var privateProperty = "visible only within class <strong>and</strong> subclasses";<br />

public var publicProperty = "visible everywhere";<br />

}<br />

Statements 225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!