# Accessing object on stage from class

**URL:** <https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143>\
**Category:** flash\
**Created:** [May 12, 2008, 10:44pm UTC](https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143 "2008-05-12T22:44:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackcoma](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@blackcoma](https://forum.kirupa.com/u/blackcoma)\
**Post date:** [May 12, 2008, 10:44pm UTC](https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143/1 "2008-05-12T22:44:26Z")

</div>

Hi,  
I’m creating a game and I want to test if an object (created by a class)  
hit the main character (created on the stage)  
I tried referencing the main character in the class (parent.main\_character),  
but it states that it doesn’t recognize that instance name.

How can I reference an object on the main stage through a class?

Thanks.

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [May 12, 2008, 10:49pm UTC](https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143/2 "2008-05-12T22:49:29Z")

</div>

Have you tried:

```auto

parentObject.getChildByName("childName");

```

---

<div class="post-metadata">

**Author:** ![congyaan](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@congyaan](https://forum.kirupa.com/u/congyaan)\
**Post date:** [May 13, 2008, 3:57am UTC](https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143/3 "2008-05-13T03:57:16Z")

</div>

I think you should better make a function to reference the object which created on the stage and assign it to a variable.

var myOwnObj:Object = new Object();  
public function getMyOnwObj():Object  
{  
return myOwnObj;  
}

when you want the myOwnObj then you can call this function,if you put this function in a public class then it can be called every where,  
if you want to disable the object then you just change the function only.

---

<div class="post-metadata">

**Author:** ![blackcoma](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@blackcoma](https://forum.kirupa.com/u/blackcoma)\
**Post date:** [May 13, 2008, 4:16am UTC](https://forum.kirupa.com/t/accessing-object-on-stage-from-class/260143/4 "2008-05-13T04:16:15Z")

</div>

Anogar, it doesn’t work.  
I tried:

```php
if(this.hitTestObject(parent.getChildByName("square"))) trace("yeah");

```

and

```php
if(this.hitTestObject(parentObject.getChildByName("square"))) trace("yeah");

```

and

```php
if(this.hitTestObject(stage.getChildByName("square"))) trace("yeah");

```

and

```php
if(this.hitTestObject(Stage.getChildByName("square"))) trace("yeah");

```

(square is the name of the object on the stage)  
They all give me this error:  
1119: Access of possibly undefined property square through a reference with static type Class.

any other suggestions?  
Thanks
