vendredi 16 septembre 2016

Mouse Events in Flash

I have just started an online class on Flash and ActionScript 3.0 and I have been having troubles with Mouse Events, especially with the CLICK class.

So I am trying to create a basic division calculator, but I can't seem to understant my error with the button. So this is the code that is not working :

public function U1A4_DivEtMod() {
        btnSoumettre.addEventListener(MouseEvent.CLICK, divise);
    }

    private function divise (event:MouseEvent):void {
        monFormat.font = "Arial";
        monFormat.size = 20;
        monFormat.bold = true;
        monFormat.color = 0xFFFFFF;

        monMessage.x = 50;
        monMessage.y = 300;

        monMessage.autoSize = TextFieldAutoSize.LEFT;
        monMessage.border = true;
        monMessage.defaultTextFormat = monFormat;

        var nmb1:int;
        var nmb2:int;
        var repDiv1:int;
        var repDiv2:int;
        var repMod1:int;
        var repMod2:int;
        var nouvMessage:String;

        nmb1=int(entier1.text);
        nmb2=int(entier2.text);
        repDiv1 = nmb1 / nmb2;
        repDiv2 = nmb2 / nmb1;
        repMod1 = nmb1 % nmb2;
        repMod2 = nmb2 % nmb1;

        nouvMessage = (
            nmb1 + " / " + nmb2 + " = " + repDiv1 + "\n" + 
            nmb2 + " / " + nmb1 + " = " + repDiv2 + "\n" +
            nmb1 + " % " + nmb2 + " = " + repMod1 + "\n" +
            nmb2 + " % " + nmb1 + " = " + repMod2 );

        monMessage.text = nouvMessage;
        addChild(monMessage);
    }

I noticed that my code works when I replace btnSoumettre by this but I can click wherever I want on the application. I am trying to make the method work only when the user presses on the button itself.

This is the error Flash is giving me

1061: Appel à la méthode addEventListener peut-être non définie, via la référence de type static Class.

So my version is in french so you guys might not understand but it basically says that the method addEventListener is not defined with a static class reference.

Thanks a lot for your help!

Aucun commentaire:

Enregistrer un commentaire