#OnDrag event listener

1 messages · Page 1 of 1 (latest)

raw glacier
#

Locally I can use dragControls.addDragEventListener("selectend", func) by adding // @ts-ignore

When I upload to glitch I am getting a type script error
Uncaught TypeError: Cannot read properties of undefined (reading 'addDragEventListener')

What is the proper way to add event listener to drag controls, when I use the addeventlistener function it doesn't do anything

if(dragControls) {
//dragControls.addDragEventListener("selectend", func) ?
dragControls.addEventListener("selectend", func) ?
}

smoky slate
#

How are those dragControls referenced / how do you assign them?

#

Your code looks fine, looks rather like "wherever dragControls comes from" might be incorrect

raw glacier
#

const dragControls = GameObject.getComponent(this.gameObject, DragControls)
const func = () => {
console.log("Drag Ended!")
this.gameObject.position.set(this.currentCubeBelow.position.x,
this.gameObject.position.y,
this.currentCubeBelow.position.z)
this.selectEndEventListener = 0;
}

    if(this.selectEndEventListener==0) {
        if(dragControls) {
            //dragControls.addDragEventListener("selectend", func)
            dragControls.addEventListener("selectend", func)
            console.log(dragControls)
        }
        this.selectEndEventListener = 1;
    }
#

trying to get the cactus to snap to the center of the tile when i stop dragging

smoky slate
#

This

const dragControls = GameObject.getComponent(this.gameObject, DragControls)

should be fine – how are you importing DragControls?

Also, could you clarify what addDragEventListener is? I don't think that exists, you should probably use addEventListener(dragstart) and so on

raw glacier
#

wait that is probably it, i'm not importing dragcontrols from the right location, it was importing from - import {DragControls} from "three/examples/jsm/controls/DragControls";

#

there is a class DragControls with method - addDragEventListener in the engine/engine-components folder

#

should I be importing that class?

raw glacier
#

works now, thank!