# Global variables

**URL:** <https://forum.kirupa.com/t/global-variables/265334>\
**Category:** Uncategorized\
**Created:** [July 7, 2008, 8:29pm UTC](https://forum.kirupa.com/t/global-variables/265334 "2008-07-07T20:29:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)\
**Post date:** [July 7, 2008, 8:29pm UTC](https://forum.kirupa.com/t/global-variables/265334/1 "2008-07-07T20:29:24Z")

</div>

Is there any way to create variables that are available to access throughout other classes/functions? Something like ‘\_root.thisVar = 1’ in AS2 - but without using event handlers to retrieve the info?

Just a curious little question!

Many thanks.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 7, 2008, 8:36pm UTC](https://forum.kirupa.com/t/global-variables/265334/2 "2008-07-07T20:36:09Z")

</div>

You can create classes that are built on the Singelton pattern to create ‘global variables’ but in general it’s something you want to stop doing since it leads to pretty poor project architecture.

---

<div class="post-metadata">

**Author:** ![partimer](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@partimer](https://forum.kirupa.com/u/partimer)\
**Post date:** [July 7, 2008, 8:40pm UTC](https://forum.kirupa.com/t/global-variables/265334/3 "2008-07-07T20:40:24Z")

</div>

Thanks sekasi - I figured there must be a way but I was looking to use it as a workaround to a problem - rather than find the correct solution! Quite a learning curve from as2!

Cheers again.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 7, 2008, 8:50pm UTC](https://forum.kirupa.com/t/global-variables/265334/4 "2008-07-07T20:50:41Z")

</div>

What you can do is create custom events that pass parameters to listeners further down the display list… It’s not awesome either, but it’s pretty decent encapsulation 😛
