Basic Class Structure


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package {
  2.  
  3. // IMPORTS
  4. import flash.display.*;
  5.  
  6. // CLASS DEFINITION
  7. // must match file name (MyClass.as)
  8. // convention says start with a capital
  9. public class MyClass extends MovieClip {
  10.  
  11. // INSTANCE VARIABLES or PROPERTIES
  12. private var instanceVariable:String = "I'm an instance variable";
  13. public var myProperty:String = "I could be a property";
  14.  
  15. // CONSTRUCTOR
  16. // runs when an instance of MyClass is created
  17. // must match class name
  18. public function MyClass():void {
  19. trace("instanceVariable: "+instanceVariable);
  20. }
  21.  
  22. // METHODS
  23. private function doSomething():void {
  24. trace("myProperty: "+myProperty);
  25. }
  26. }
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.