Something's Different: Tips for Making a Painless Migration to ActionScript 3
- Accessing class methods
- Controlling the z-index of display objects
- Mouse events
- Dynamic library items
There are many necessary ActionScript tasks used to create common Flash functionality. With all of the updates and changes made to ActionScript, figuring out how to accomplish some of the most simple tasks can require digging through search results or even Flash Help. This article will help alleviate a little of that pain by providing useful tips to help make the migration. There aren’t any lengthy explanations here, just quick, painless solutions for a few of your more pressing ActionScript problems.
Accessing class methods
Problem: Sub-classes can no longer access their super classes’ private methods. This is because private is now truly private.
Solution: Use protected if you want to have access to an inherited class method.
Code: In the following example, class B can access getProtected, but not the getPrivate method. Commenting-out the getPrivate method produces successful results.
package { import flash.display.*; public class A extends Sprite { public function A():void { } protected function getProtected():String { return "protected method"; } private function getPrivate():String { return "private method"; } } } package { public class B extends A { public function B():void { super(); trace(super.getProtected()); trace(super.getPrivate()); } } }