I'm having a couple problems with getDefinitionByName. What im trying to do is the following.

I load in a XML file with several items in an inventory which contain a couple details.

Eg
PHP Code:
<items>

   <
item>
      
      <
description>A simple hat</description>
      <
classname>Hat</classname>

    </
item>

    <
item>

      <
description>A pair of pants</description>
      <
classname>Pants</classname>

    </
item>

</
items
Then in my code I try to make an instance of these classes by using the following

PHP Code:
var ClassReference:Class = getDefinitionByName() as Class;
var 
item:Item = (new ClassReference as Item); 
The problem I'm getting is an error saying
ReferenceError: Error #1065: Variable Hat is not defined.

Now I got around this problem by adding the following right before my script

var hat:Hat;

But this seems like a really bad hack since I could have thousands of different items. So having to place a list of them before this line seems a bit overkill.

Any ideas why this problem occurs?

Thanks