Flash / Flex / ActionScript/Class/Access Control Modifiers — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:14, 26 мая 2010
Содержание
- 1 Access Control Modifiers for Classes are listed before the keyword class in a class definition
- 2 Declares a new private property called _id within the Example class:
- 3 Inherit protected variable
- 4 Internal variable
- 5 private variable is not inherited
- 6 protected member variables
- 7 The Internal Details
Access Control Modifiers for Classes are listed before the keyword class in a class definition
attribute class ClassIdentifier {
}
To add the public attribute to the MyClass class
package com.wbex {
public class MyClass {
}
}
Explicitly indicate that MyClass is used within the com.wbex package only with internal attribute
package com.wbex {
internal class MyClass {
}
}
A class defined with the internal attribute can be used within its containing package only.
Declares a new private property called _id within the Example class:
package {
public class Example {
private var _id:String;
}
}
Inherit protected variable
class Toaster
{
protected var finish:String = "Reflective Silver";
}
class HeatedResistorToaster extends Toaster
{
public function HeatedResistorToaster()
{
trace(finish); //Reflective Silver
}
}
Internal variable
class Bread
{
internal var toastiness:Number = 0;
}
class Pillow
{
public function Pillow()
{
var b:Bread = new Bread();
b.toastiness = 20; //Compiler error! You can"t do this!
}
}
private variable is not inherited
class Toaster
{
private var finish:String = "Reflective Silver";
}
class HeatedResistorToaster extends Toaster
{
public function HeatedResistorToaster()
{
trace(finish); //Compiler error! We don"t have a finish.
}
}
protected member variables
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var r = new Rectangle( );
r.setSize(4,5);
trace(r.getArea( ));
var s = new Square( );
s.setSize(4,5);
trace (s.getArea());
}
}
}
class Rectangle {
protected var w = 0;
protected var h = 0;
public function setSize (newW, newH) {
w = newW;
h = newH;
}
public function getArea ( ) {
return w * h;
}
}
class Square extends Rectangle {
override public function setSize (newW, newH) {
if (newW == newH) {
w = newW;
h = newH;
}
}
}
The Internal Details
package {
public class SomeClass {
public function instanceMeth ( ):void {
function nestedFunc ( ):void {
trace(a);
}
}
}
}
var a:int = 15;