开发者

dispatchEvent doesn't work in secondary class

开发者 https://www.devze.com 2023-02-03 23:15 出处:网络
I have this problem here: I have a SWF called Application.swf that loads another SWF called jeu.swf. My main class (don\'t know how to call it haha), is called Main.as.

I have this problem here:

I have a SWF called Application.swf that loads another SWF called jeu.swf.

My main class (don't know how to call it haha), is called Main.as. Another class is called actionObjets.as

When I call:dispatchEvent(new MicroJeuEvent(MicroJeuEvent.JEU_TERMINE, 8, "")); (Provided by my teacher), it works perfectly from Main.as, it works perfectly.

But when I call it from actionObjets, it doesn't work. No error either.

I tried putting this line in a static function, doesn't work either.

Why can I dispatch an Event from my main class and not from another one? I'm not a programmer and I just don't get a few of the basic principles of as3. Is there a way of doing differently? Is so, i'm not good and开发者_如何学编程 i'd need to know what to do exactly! haha. Thx!

/*--Finir Jeu--*/
        public function finirJeuFonction(methode, points):void{
            var faceDeGagner:Array = new Array("Vous êtes mort","Vous avez sauté par la fenêtre","Vous avez éteind le feux","Vous avez tiré votre soeur déguisée en zombie","Votre soeur aime se déguiser en zombie","Vous avez exterminé l'homme louche");

            switch(monterJeu._Difficulte){
                case 0:
                    _creationObjet.fenetreMobilier.parent.removeChild(_creationObjet.fenetreMobilier);
                    _creationObjet.armoireMobilier.parent.removeChild(_creationObjet.armoireMobilier);
                    break;
                case 1:
                    _creationObjet.zombieMobilier.parent.removeChild(_creationObjet.zombieMobilier);
                    _creationObjet.litMobilier.parent.removeChild(_creationObjet.litMobilier);
                    _creationObjet.tablePCMobilier.parent.removeChild(_creationObjet.tablePCMobilier);
                    _creationObjet.coffreMobilier.parent.removeChild(_creationObjet.coffreMobilier);
                    break;
                case 2:
                    _creationObjet.armoireCoteMobilier.parent.removeChild(_creationObjet.armoireCoteMobilier);
                    _creationObjet.litMobilier.parent.removeChild(_creationObjet.litMobilier);
                    _creationObjet.hommeMobilier.parent.removeChild(_creationObjet.hommeMobilier);
                    _creationObjet.C4Mobilier.parent.removeChild(_creationObjet.C4Mobilier);
                    _creationObjet.boutonC4Mobilier.parent.removeChild(_creationObjet.boutonC4Mobilier);
                    break;
            }
            _creationObjet._creationBackground.getBackgroundStage.parent.removeChild(_creationObjet._creationBackground.getBackgroundStage);
            //Chronometre.horloge.stop();

            _creationObjet.messageFinMC.visible = true;
            _creationObjet.messageFinMC.nbrePointsTxt.text = points;
            _creationObjet.messageFinMC.messageFinTxt.text = faceDeGagner[methode];

            dispatchEvent(new MicroJeuEvent(MicroJeuEvent.JEU_TERMINE, 8, ""));
        }


Try and setup your classes similar to the following:

In the Main class...

package 
{
    import com.ActionObjets;
    import flash.display.Sprite;
    import flash.events.Event;

    public class Main extends Sprite
    {
        public function Main()
        {
            init();
        }

        private function init():void
        {
            var actionObjets:ActionObjets = new ActionObjets();
            actionObjets.addEventListener(Event.COMPLETE, completeHandler);
            actionObjets.finirJeuFonction(); 

        }// end function

        private function completeHandler(e:Event):void
        {
            trace("complete");

        }// end function

    }// end class

}// end package

and in the ActionObjets Class:

package com
{
    import flash.events.EventDispatcher;
    import flash.events.Event;

    public class ActionObjets extends EventDispatcher
    {
        public function ActionObjets() {} // end function

        public function finirJeuFonction():void 
        {
            dispatchEvent(new Event(Event.COMPLETE, true));

        }// end function

    }// end class

}// end package

that should work.

0

精彩评论

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