开发者

Error #1034, with a MouseEvent

开发者 https://www.devze.com 2023-01-28 11:26 出处:网络
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.

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(p开发者_如何学JAVAersonnageJeu);
        }
        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!


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.


You are trying to cast 3 to the class mouvement into the test function:

   function test(e:MouseEvent){
        pCoordonnees = stage.mouseX;
        trace(pCoordonnees);
        new mouvement().mouvement(3); // <-- here your error
    }

If you have only a function into your class you don't need to create a class but you can put on the function alone:

package cem
{
        public function mouvement(blabla):void {
            trace(blabla);
        }
}

and now you can call the mpuvement function normally into you test function:

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

精彩评论

暂无评论...
验证码 换一张
取 消