Skip to content

ButtonHelper "over" and "out" event swaps after changing enabled property of it #941

Open
@wanted28496

Description

@wanted28496

I am using button helper in my code for creating buttons and after clicking I use the enabled property of the button helper to disable the button and after few seconds I set the enabled property to true but after setting the enabled property to true the properties I had set before clicking gets swap

I have attached images depicting the problem I faced
Image MathFact_1: Depicts my original animation I need at "out"
Image MathFact_2: Shows the over animation
Image MathFact_3: Shows the down animation
Image MathFact_4: Shows the over animation after the click event is fired
Image MathFact_5: Shows the out animation after the click event is fired

mathfact_4
mathfact_5
mathfact_1
mathfact_2
mathfact_3

Here's the code for the same

class BaseButton extends createjs.ButtonHelper{
    currentListener:any;
    currentState: GameButtonState = GameButtonState.INACTIVE;
    preOverState: GameButtonState;
    keyBinds: number[] | null = null;
    public KBListener: any;
    isListening: boolean = false;

    constructor(public target: createjs.MovieClip){
        super(target,"up", "over", "down",false);
        this.target.on("click",this.buttonEvent.bind(this));
    }

    protected addListener(){
        if(!this.isListening)
        {
            console.log(this.currentListener);
            this.isListening=true;
            this.enabled = true;
            this.target.gotoAndStop("up");
        }
    }

protected buttonEvent(event):boolean{
        console.log(event);
        debugger;
        this.removeListener();
        setTimeout( () => {
            this.addListener();
        }, 5000)
        return true;
    }


 protected removeListener():void{
        this.isListening=false;
        this.enabled = false;
        this.setMouseDefault();
    }

 protected setMouseDefault():void{
        let element: HTMLElement | null = window.document.getElementById("canvas");
        element!.style.cursor = "default";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions