Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 133

Programming actionscript 3.0
Table of Contents

Advertisement

You can use the following example to see how each of the access control specifiers affects
inheritance across package boundaries. The following code defines a main application class
named AccessControl and two other classes named Base and Extender. The Base class is in a
package named foo and the Extender class, which is a subclass of the Base class, is in a package
named bar. The AccessControl class imports only the Extender class and creates an instance of
Extender that attempts to access a variable named
variable is declared as
str
following excerpt:
// Base.as in a folder named foo
package foo
{
public class Base
{
public var str:String = "hello"; // change public on this line
}
}
// Extender.as in a folder named bar
package bar
{
import foo.Base;
public class Extender extends Base
{
public function getString():String {
return str;
}
}
}
// main application class in file named ProtectedExample.as
import flash.display.MovieClip;
import bar.Extender;
public class AccessControl extends MovieClip
{
public function AccessControl()
{
var myExt:Extender = new Extender();
trace (myExt.testString);
trace (myExt.getString()); // error if str is private or internal
}
}
}
so that the code compiles and runs as shown in the
public
// error if str is not public
that is defined in the Base class. The
str
Inheritance
133

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents