Error #1034, with a MouseEvent

I am making a basic point n' click game and I came upon this error: TypeError: Error #1034: Type Coercion failed: cannot convert 3 to cem.mouvement.

Here's my script:

package cem {
    import flash.events.Event;
    import flash.display.MovieClip;
    import cem.microjeux.events.InfoJeuEvent;
    import cem.mouvement;
    import flash.events.MouseEvent;

    public class monterJeu extends MovieClip
    {
        private static var pType:String = "type";
        private static var pNom:String = "testNom";
        private static var pCourriel:String = "test@hotmail.com";
        private static var pDifficulte:int = 0;
        private static var pLangue:int = 0;
        private static var pTitre:String = "Veuillez sortir";
        private static var pVersion:String = "1.5";
        private static var pCoordonnees:Number;

        private var environnementJeu:environnement = new environnement();
        private var personnageJeu:personnage = new personnage();

        public function monterJeu():void
        {
            jouer(pNom,pDifficulte,pLangue);
            dispatchEvent(new InfoJeuEvent(pType,pNom,pCourriel,pTitre,pVersion));
            stage.addEventListener(MouseEvent.CLICK, test);
        }

        public function jouer(PNom:String,PDifficulte:int,PLangue:int):void
        {
            addChild(environnementJeu);
            addChild(personnageJeu);
        }
        function test(e:MouseEvent){
            pCoordonnees = stage.mouseX;
            trace(pCoordonnees);
            mouvement(3);
        }
    }
}

And on mouvement();

package cem
{
    public class mouvement {

        public function mouvement(blabla) {
            trace(blabla);
        }
    }
}

I searched everywhere I could, and didn't find anything. I have no instances on the stage. Everything is imported on the first frame. I am kind of a beginner (let's say i'm no good at programming), so you can notify at the same time if you something that needs to be corrected. (BTW, the strange words are in french ;D) Thanks!

Answers


The error is due to you trying to cast 3 to mouvement.

I think what you want is something like

function test(e:MouseEvent){
    pCoordonnees = stage.mouseX;
    trace(pCoordonnees);
    var mouve:mouvement = new mouvement(3);
}

Notice that you have to have new in order to create a new instance of a class.

On another note, you should capitilize classes so they stand out better. So I would name the class Mouvement.


Need Your Help

Can't have Nuget.config in source control?

tfs nuget visual-studio-2015

In one of our projects, I've recently converted from the (now broken) old-school MSBuild based automatic package restore to the shiny new automatic package restore in Nuget 3.0 (Visual Studio 2015 ...