Abstract methods in flash

So if you've got any sort of programming background, you'd probably notice the omission of the abstract  keyword in AS3. As it relates to methods, an abstract  method in a class is one that should never be called directly, and should only be overwritten by a class which extends the original class.

Here's a technique for replicating that in AS3.

The root class:

package {
    public class Popup extends Sprite {       
        public function reveal():void {
            // to be defined in subclasses
            throw new Error("Abstract method reveal must be overridden");
        }
    }
}

And the class that extends it:

package {
    public class VideoPopup extends Popup {       
        public override function reveal():void {
            this.visible = true;
        }
    }
}

So if the base reveal  method is called, an error is thrown.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


 

  Country flag





Live preview

January 6. 2009 07:04