# Instantiate class that children have access to globally?

**URL:** https://forum.kirupa.com/t/instantiate-class-that-children-have-access-to-globally/332032
**Category:** flash
**Created:** [January 5, 2014, 6:57pm UTC](https://forum.kirupa.com/t/instantiate-class-that-children-have-access-to-globally/332032 "2014-01-05T18:57:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tpann](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tpann](https://forum.kirupa.com/u/tpann)
#### Post date: [January 5, 2014, 6:57pm UTC](https://forum.kirupa.com/t/instantiate-class-that-children-have-access-to-globally/332032/1 "2014-01-05T18:57:48Z")

</div>

Not sure if the title of this is perfectly descriptive of what I’m looking for but here’s what I’m looking for:

I want a class that I’ll call GlobalCounter that has a getter called next. Class Parent would instantiate gc = new GlobalCounter() and then each gc.next call increments a parameter on GlobalCounter and returns an integer one greater than the last. So on Parent:

```php
trace(gc.next); // 1
trace(gc.next); // 2
trace(gc.next); // 3

```

Fine so far. But what I want is for all of Parent’s children and its children’s children to have access to GlobalCounter’s next value, so that after the above, if SubChild2\_2 asks for GlobalCounter’s next value it would get 4.

I know that I could pass gc from Parent to each of its children and from each Child to each SubChild, but I’m hoping to avoid that. I want to call GlobalCounter once from Parent.

Is this possible?
