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

Public Attribute Keyword

Public is the default attribute keyword for functions and properties in both ActionScript 2 and 3. Public functions and properties are completely accessible to other classes. AS3 offers a few additional features that set its public attribute apart from the AS2 version.

AS2: Public Attribute Keyword

Public functions and properties are visible to any class in a project. The default keyword in AS2 is public, which allows any class to access class methods or properties that are not typed.

Since the ToString function is public, any class that imports and instantiates the PublicExample object can access the function and retrieve the return value of ToString.

AS3: Public Attribute Keyword

In ActionScript 3, the default attribute keyword for functions and properties is also public. While attribute keywords are not required, they are standard.

The public keyword provides the same level of access to external classes as in AS2, but if a class with public functions is inherited, it’s possible to override the public functions by redefining them in a subclass.

Subclasses can return new values and invoke code differently within methods that they override, but must accept and return the same value types. For example, if a superclass contains a method that returns a String, a subclass that overrides the method cannot return a Boolean. Instead, the return type must be a String.

If you wanted to return the hierarchy of classes when calling the ToString function, you could also invoke the superclass version of the ToString function.

  • + Share This
  • 🔖 Save To Your Account