# Access global object with another global object of a different class - Please Help :S

**URL:** <https://forum.kirupa.com/t/access-global-object-with-another-global-object-of-a-different-class-please-help-s/324621>\
**Category:** flash\
**Created:** [August 30, 2011, 5:16pm UTC](https://forum.kirupa.com/t/access-global-object-with-another-global-object-of-a-different-class-please-help-s/324621 "2011-08-30T17:16:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taloton](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@Taloton](https://forum.kirupa.com/u/Taloton)\
**Post date:** [August 30, 2011, 5:16pm UTC](https://forum.kirupa.com/t/access-global-object-with-another-global-object-of-a-different-class-please-help-s/324621/1 "2011-08-30T17:16:23Z")

</div>

Hello,

I would appreciate any help that I can receive with my issue. I will explain the circumstances then ask what to do.

I have 2 classes:

bullet class:Extends MovieClip and stores information about bullets while handling their movement and properties.

enemy class:Extends MovieClip and simply so far stores the x,y co-ordonates of the enemy.

I want the bullet to home onto the enemy object in the movement function by referencing the x and y position of the enemy.

Here’s the code:

```auto

**//Main as3 file
**
stage.addEventListener(MouseEvent.MOUSE_DOWN,clk);//stuff that happens on click

function clk (e:MouseEvent){
    shotcnt += 1;
    shotobj.push(new pshot(player.x,player.y));
    addChild(shotobj[shotcnt]);
    shotobj[shotcnt].addEventListener(Event.ENTER_FRAME,shotobj[shotcnt].movement);
}

```

```auto

**//pshot class file**
package {
    
    import flash.display.MovieClip;
    
    public class pshot extends MovieClip {
        
        public var xvel =0;
        public var yvel =0;
        public var sped = 10;
                          
        public function pshot(mox, moy) {
            // constructor code
            this.x = mox;
            this.y = moy;
            
            this.yvel = ((mouseY)) / Math.sqrt( Math.pow(mouseY,2) + Math.pow(mouseX,2) )
            this.xvel = ((mouseX)) / Math.sqrt( Math.pow(mouseY,2) + Math.pow(mouseX,2) )
        }
        public function movement(e:String)
        {

                        var ex = enemy.x; **//this is where I get the error because i can't access the enemy object. I also tried stage.enemy.x and it failed too.**
                        
            this.x += sped*this.xvel;
            this.y += sped*this.yvel;
        }
    }
}

```

Please help me allow my shot to reference the enemy object.

Thanks so much  
-Taloton
