Jump to content

This context matters


Fenopiù
 Share

Recommended Posts

Good morning guys!

I've created a class to manage my sliders in Phaser 2.6.2 with Typescript.

I create an object slider like this in file a.ts:

let slider = new Slider(game, x, y, width, height, mycallback);

mycallback is like that:

export function mycallback(value: number): void
{
   usedvalue = value;
}

My slider class is like that:

export class Slider extends Phaser.Group
{
    protected value              : number;
    constructor
       (
            game                 : Phaser.Game,
            x                    : number,
            y                    : number,
            width                : number,
            height               : number,
            onClickCallback      : Function
       )
    {
            super(game);
            console.log(this);
    }

    setParameter(sender)
        {
            this.value = sender.width - sender.x;
            console.log(sender);
            console.log(this);
            this.onClickCallback(this.value);
            sender.onClickCallback(this.value);
        }
}

Ok, now both this.onClickCallback(this.value); and sender.onClickCallback(this.value); return an error "onClickCallback is not a function".

The first console.log(this), the one inside the constructror, give me the right log writing Slider and all his values.

The second console.log(this) and console.log(sender), the ones in setParameter, return me game.

What is my error?

How can I resolve this?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...