Skip to main content
September 5, 2010
Question

Still can't get classes perfectly... HELP!

  • September 5, 2010
  • 1 reply
  • 580 views

I'm a decent as 3 programmer but I still cannot figu

re out how to use classes 100%. I've always programmed with everything on the main timeline in frame

1 with a ton of functions. I'm working on a big project and I'd like to clean this up a little and it makes sense to build classes for t

hings. However I cannot figure out the communication between classes.

I have a DocClass. That DocClass import Class_A and Class_B:

public class DocClass extends MovieClip {
  public var _instance:DocClass;
  public var class_a:Class_A;
  public var class_b:Class_B;
 
  public function DocClass() {
   // constructor code
   trace("main constructor");
   class_a = new Class_A();
   //class_b = new Class_B();
  }
 
  public static function myFunction():void{
   trace("here at my function");
  }
}

From the main timeline I can call the method myFunction just fine. However, I cannot call any function in Class_A or Class_B from the main timeline, why?

Class_A

public class Class_A {
 
  public function Class_A() {
   // constructor code
   trace("class a constructor")  }
 
  public static function myAFunction():void{
   trace("here at a my function");
  
  }

}

Doc Class loads Class_A but Class_A isn't available to call from the main timeline....

This topic has been closed for replies.

1 reply

September 5, 2010

Okay, so I just guessed and made some headway. I created public variables to reference the classes but they

don't work.

class_a.myAFunction(); // doesn't work from anywhere

Class_A.myAFunction(); // does work

Why doesn't my public var class_a:Class_A work?

Inspiring
September 5, 2010

Static methods and properties belong to class - not instance of class. Thus, one cannot call them on an instance.