# What to extend to allow drag

**URL:** https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693
**Category:** Phaser 3
**Created:** [October 15, 2020, 5:10pm UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693 "2020-10-15T17:10:06Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Pazvanti](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pazvanti/32/3900_2.png) [@Pazvanti](https://phaser.discourse.group/u/Pazvanti)
#### Post date: [October 15, 2020, 5:10pm UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/1 "2020-10-15T17:10:06Z")

</div>

I have a class where I am building a complex object consisting of multiple sprites. I want to have the object generated by it draggable. I have the set/get for both x and y implemented. When I call setDraggable() on such an object I get the following error: Uncaught TypeError: Cannot set property ‘draggable’ of undefined

My assumption is that I need to make it interactive first by calling a setInteractive(), but since it is a custom made object I don’t have such a method. I probably need to extend a certain class to have this functionality, but don’t know which one.

My current class looks something like this:

```
class MyComplexObj {
    constructor(scene) {
        scene.add.sprite(...);
        scene.add.sprite(...);
        scene.add.sprite(...);
    }

    set x(pos) {
        // set x for all sprites
    }

   set y(pos) {
       // set y for all sprites
   }
}
```

---

<div class="post-metadata">

### Author: ![seyuup](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@seyuup](https://phaser.discourse.group/u/seyuup)
#### Post date: [October 15, 2020, 7:19pm UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/2 "2020-10-15T19:19:55Z")

</div>

Maybe have you class extend [Phaser.GameObjects.GameObject](https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObject.html)  
Then with you instance of MyComplexObj you can call .setInteractive()

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [October 16, 2020, 2:33am UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/3 "2020-10-16T02:33:40Z")

</div>

Can you use a Container instead?

---

<div class="post-metadata">

### Author: ![Pazvanti](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pazvanti/32/3900_2.png) [@Pazvanti](https://phaser.discourse.group/u/Pazvanti)
#### Post date: [October 16, 2020, 4:52am UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/4 "2020-10-16T04:52:45Z")

</div>

This partially worked. Extending GameObject no longer triggers the error and I can call setInteractive().  
However, I still can’t drag the element. I think I know why though.  
Since this is a custom made object, it does not know what are the borders, so it does not know when I actually click on it.  
Investigating further, but I believe I am on the right path. Thanks

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [October 16, 2020, 2:21pm UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/5 "2020-10-16T14:21:04Z")

</div>

Pass a hit area to `setInteractive()`. Or extend Zone instead.

---

<div class="post-metadata">

### Author: ![Pazvanti](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pazvanti/32/3900_2.png) [@Pazvanti](https://phaser.discourse.group/u/Pazvanti)
#### Post date: [October 16, 2020, 4:21pm UTC](https://phaser.discourse.group/t/what-to-extend-to-allow-drag/7693/6 "2020-10-16T16:21:14Z")

</div>

Thanks. Will have to look into how to provide the sprite that is the background as the hit area.
