title: Is it possible to have a variable with specific class reference type in AS3?
body: <p>Coming from a Delphi background, I am used to be able to have class references/pointers of a specific superclass, example:</p>
  
  <pre><code>#!pas
  var
    niceVar: class of TClassOne; // Delphi style
    badVar: class; // Only? allowed AS3 style to the best of my knowledge
  
  begin
    niceVar := x;
    badVar := x;
  
    niceVar.staticMethodSpecificToTClassOne;
    TClassOne(badVar).staticMethodSpecificToTClassOne;
  end;
  </code></pre>
  
  <p>What this means is that I don't have to cast my variables to a specific class; they are of the correct Class beforehand.  This also means that compile-time checking can be performed to make sure proper members are being accessed and I don't have to check that niceVar is in fact of class TClassOne if niceVar was passed to a method.</p>
  
  <pre><code>#!pas
  procedure test(var x: class of TClassOne);
  begin
    x.someStaticMethod(true);
  end;
  
  // An entry point
  var
    niceVar: TClassTwo; // Does not inherit from TClassOne
  
  begin
    test(niceVar); // Error - niceVar does belong to the TClassOne "family"
  end;
  </code></pre>
  
  <p>So just like a variable storing an object can be for a specific type and only objects of that class or subclasses of it are accepted, so to does "class of AClass" allow for variables of a specfic class to be limited to references to a certain class or those inherited from it.</p>
  
  <p>I hope that makes sense somehow; I don't know of specific nomenclature for the whole "class of SuperClass" thing.</p>
  
  <p>So I'd like to do the same in AS3 as having variables/properties/parameters of type Class does not cut the mustard; its kind of like having all object variables/properties/parameters simply being Object instead of their proper, specific type.</p>
  
  <hr>
  
  <p><strong>Edit #1 - 2011-02-14 13:34</strong>
  Syntax highlighting is messed up here; I want the code to be recognized as Object Pascal.  Looking forward to <a href="https://meta.stackexchange.com/questions/72082/changes-to-syntax-highlighting">this</a>.</p>
  
  <hr>
  
  <p><strong>Edit #2 - 2011-02-14 15:11</strong>
  Here is an example of what I would like to achieve with this in AS3.</p>
  
  <p><em>Current code</em></p>
  
  <pre><code>public function set recordClass(aRecordClass: Class): void 
  {
    if (!extendsClass(aRecordClass, TRecord)) 
    {
      throw new Error("TDBTable - Invalid record class passed.");
        return;
    }
    _recordInstance = new aRecordClass(this); // Compiler has no idea of the classes constructor signature, but allows this regardless.
  }
  </code></pre>
  
  <p><em>What I'd like to be able to do</em></p>
  
  <pre><code>public function set recordClass(aRecordClass: TRecordClass): void 
  {
    _recordInstance = new aRecordClass(this); // Compiler will know that I am creating a TRecord
  }
  </code></pre>