Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > ActionScript

  • Print
  • + Share This
This chapter is from the book

Private Attribute Keyword

As more attribute keywords have been added to the ActionScript language, some of the existing functionality has changed to accommodate the additions. The private attribute keyword is a prime example: At first glance the changes may seem minor, but they actually require the addition of an entirely new attribute keyword.

AS2: Private Attribute Keyword

In ActionScript 2 the private attribute keyword is used to restrict access to methods and properties. Where public allows access to any class, private limits access to the class that defines it and any subclasses of the defining class.

The private keyword is extremely useful when writing methods or properties that are either of no use to other classes or contain information that needs to be kept secure.

AS3: Private Attribute Keyword

In ActionScript 3 the private attribute keyword is a lot more private than in AS2. Not only is a private function, property, or namespace inaccessible from other classes, private items can no longer be inherited either. If you need to keep a function, property, or namespace hidden from other classes, but you still want them to be inherited, you can use a new keyword called protected. The protected keyword allows access only to subclasses. Even classes in the same package are not allowed access through protected.

Since the protected keyword allows access to subclasses, subclasses can define new values for the protected properties that they inherit. Subclasses cannot override protected functions, however.

  • + Share This
  • 🔖 Save To Your Account