# Trying to access a var that's inside a class....? help

**URL:** <https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545>\
**Category:** Uncategorized\
**Created:** [June 6, 2008, 8:22pm UTC](https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545 "2008-06-06T20:22:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rustybucket145](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rustybucket145](https://forum.kirupa.com/u/rustybucket145)\
**Post date:** [June 6, 2008, 8:22pm UTC](https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545/1 "2008-06-06T20:22:53Z")

</div>

Hi all! Well I’ve been working on this for a couple of days now and just can’t seem to get it to work right… I’m still getting my feet wet with as3 and like it more and more everytime I use it… almost.

Anyways, here’s where I’m running into trouble.

Here’s a dumbed down version of my project with all the other usless drivel excluded. Basically what I’m trying to do is declare a var and give it a value in my class. Then I want to be able to display that value on the stage and use it in the main timeline. Seems simple enough…

I need to be able to pass the var from the class to the main timeline for use… Any help on this would be GREATLY appreciated.

Thanks.

```auto
//Actionscript code on first frame of main timeline

//Imports my class... works fine.
import folder.testing.TestClass;

var testClass:TestClass = new TestClass();

//Class Code
package folder.testing {
	public class TestClass {
		
		public var someNumber:Number;
		
		public function TestClass() {
			trace("test class working");
			someNumber = "1234";
			trace(someNumber);
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Jeds](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@Jeds](https://forum.kirupa.com/u/Jeds)\
**Post date:** [June 7, 2008, 7:01am UTC](https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545/2 "2008-06-07T07:01:32Z")

</div>

in your timeline or document class

```auto

var test:TestClass = new TestClass()
trace(test.someNumber)

```

---

<div class="post-metadata">

**Author:** ![rustybucket145](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rustybucket145](https://forum.kirupa.com/u/rustybucket145)\
**Post date:** [June 7, 2008, 1:28pm UTC](https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545/3 "2008-06-07T13:28:48Z")

</div>

That did it! Thanks!!

---

<div class="post-metadata">

**Author:** ![level4designs](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/level4designs/32/2659_2.png) [@level4designs](https://forum.kirupa.com/u/level4designs)\
**Post date:** [June 7, 2008, 2:32pm UTC](https://forum.kirupa.com/t/trying-to-access-a-var-thats-inside-a-class-help/262545/4 "2008-06-07T14:32:24Z")

</div>

so can you access that variable in any class from there on out if that new “test” was created on the main timeline?

I was trying to create a new class that acted like a global variable, but when I go into my classes all over the place and try to acess it, I could not find it? should that work though? if created on the main timeline, a variable is accessed like a global in AS2.0 was?
