# Calling a class function within another class

**URL:** https://forum.kirupa.com/t/calling-a-class-function-within-another-class/309173
**Category:** flash
**Created:** [May 8, 2010, 6:11pm UTC](https://forum.kirupa.com/t/calling-a-class-function-within-another-class/309173 "2010-05-08T18:11:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lashdl](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@lashdl](https://forum.kirupa.com/u/lashdl)
#### Post date: [May 8, 2010, 6:11pm UTC](https://forum.kirupa.com/t/calling-a-class-function-within-another-class/309173/1 "2010-05-08T18:11:57Z")

</div>

Hi.  
I’ve been searching around the forums to find a solution of this problem.  
I have two classes: Monster and Player. Constructors are defined and the classes by themselves apparently works.  
My problem is that I want to get player.x inside the Monster class.

So I want to be able to do this:

inside a function of the monster:

{…  
pan = this.x - player.getX();  
…}

inside the player class:

public function getX():Number{  
return this.x;  
}

Within my .fla file i create two instances:

// do not mind the “localhost”, 31337 part.  
var player: Player = new Player(“localhost”, 31337);  
addChild(player);  
var monster:Monster = new Monster(“localhost”, 31339);  
addChild(monster);

trace(player.getX()); // works

when compiled i get:  
1120: Access of undefined property player.

thanks in advance.  
/Lasse
