0

I'm working with Actionscript 2 (not ready to upgrade yet, although it's irreverent to the problem) but I'm having trouble with OOP and classes.

I've got a "Tool" class, written like so:

class com.Tool {
  public var self:MovieClip;
  private static var Type:String;

  function Tool(T:String, X:Number, Y:Number) {
    Type = T;

    self = _root.createEmptyMovieClip("obj"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
    self._x = X;
    self._y = Y;
    self.width = 36;
    self.height = 36;

    self.onRollOver =  function() {
        trace(Type);
    }
  } 
}

I create 3 of them in the main script like so:

var toolPan:Tool = new Tool("pan", 0, 0);
var toolSquare:Tool = new Tool("square", 0, 38);
var toolLine:Tool = new Tool("line", 0, 76);

It all works great, except the onRollOver. It's supposed to output the unique "Type" string, but it always outputs "line" (the last Type Tool created) regardless which one I roll over.

Needless to say, I'm still a beginner to all this. But it seems like they're all sharing the same variable :/ How do I make these variables unique to each object created?

Thank you very much!

Tom
  • 207
  • 2
  • 18

1 Answers1

2

It's because it's type static, so the value is shared by all instances of that class. Remove it and it should work.

private var Type:String;
zeh
  • 10,130
  • 3
  • 38
  • 56