# Classes

**URL:** <https://forum.kirupa.com/t/classes/271062>\
**Category:** Uncategorized\
**Created:** [September 17, 2008, 10:43pm UTC](https://forum.kirupa.com/t/classes/271062 "2008-09-17T22:43:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_beef](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Mr\_beef](https://forum.kirupa.com/u/Mr_beef)\
**Post date:** [September 17, 2008, 10:43pm UTC](https://forum.kirupa.com/t/classes/271062/1 "2008-09-17T22:43:37Z")

</div>

Right, I haven’t touched AS in a few months now so now I have returned to it I am just as lost when I first started lol.

I think of classes as a way to reuse the same code but creating different things. So for example a class called Items which gives the traits for all things created by that class, they are all an Item but all differ slightly.

So I quickly went off to make a class;  
[AS][COLOR=#000000]class Test {  
var number:Number;  
public function getTrace() {  
number = Math.round(Math.random()\*1000);  
trace(number);  
}  
}[/AS][/COLOR]

And made a swf;  
[AS]var Test:Test = new Test();  
var Test3:Test = new Test();  
var Test2:Test = new Test();

\_root.Test3.getTrace();  
\_root.Test2.getTrace();  
\_root.Test.getTrace();[/AS]

But I only get one trace given to me, but if I swap the order so it goes Trace 3, then 2 then 1 I get three traces as I want. I think I have misunderstood something simple :crying: Why does it do that? I just wanted 3 different items to do the same thing, like 3 swords which you can all pickup, sell equip etc etc.
