8 Replies Latest reply on May 18, 2007 3:05 PM by kglad

    have a function perform a function

    spookmc
      In my game I have created a construction where a popup window calls a predefined function if OK is pressed.
      Unfortunately the function I call (bald in the script) is not performed...

      it looks like this:

      For a tile in my game I defined the method: klikAction
      Next to that I also defined an okAction (to be performed by the popup when ok is clicked)

      Popup function does show the text, but the okAction is not performed.....

      Any suggestions??

      here is my script:

      game.Tile102.prototype.klikAction = function(){
      var action:String = "normal";
      var tekst:String = "You pikc up the fax and read";
      this.gotoAndStop(16); //show fax-img without the faxpaper
      popup(tekst, action, this.okAction);}

      game.Tile102.prototype.okAction = function(){
      trace("OKACTION!!");
      game.gameState.score += 5;
      changeScore(game.gameState.score, 100);
      game.gameState.isFax = false;
      game.gameState.mouse = 2;
      _root.mouse.gotoAndStop(2);
      }

      function popup(tekst:String, action:String, okAction:Function){

      stopAllMovements();
      if(action == "normal"){
      var popup:MovieClip = _root.attachMovie("popup_mc", "PopUp", 20000, {_x:(Stage.width-390)/2, _y:(Stage.height-200)/2});
      popup.tekst_txt.text = tekst;
      //create OK button to perform okActie and close the popup
      popup.popup_btn_ok_mc.btnLabel_txt.text = "O.K.";
      popup.popup_btn_ok_mc.onRelease = function() {
      trace("hiero");
      restartAllMovements();
      popup.removeMovieClip();
      okAction.apply();
      }
      }

        • 1. Re: have a function perform a function
          kglad Adobe Community Professional & MVP
          do you see OKACTION?
          • 2. Re: have a function perform a function
            spookmc Level 1
            Thanks for your interest in problem.

            No,I do not see OKACTION!. I do see "hiero" though.

            That is exactly the problem.

            Any suggestions for futher tests?
            • 3. Re: have a function perform a function
              spookmc Level 1
              Well, maybe It is better explained with a "cleaner" script, and a debug code in it.

              I will show you the script and the oputput in the output window it generates.

              SCRIPT:

              game.Tile102.prototype.klikAction = function(){
              var tekst:String = "Je pakt de fax en leest";
              popup(tekst, this.okAction);
              for (var i in this)
              {
              trace(i+": "+this );
              }

              }

              game.Tile102.prototype.okAction = function(){
              trace("OKACTION!!");
              }

              function popup(tekst:String, okAction:Function){

              var popup:MovieClip = _root.attachMovie("popup_mc", "PopUp", 20000, {_x50, _y50});
              popup.tekst_txt.text = tekst;

              //maak een OK button die de okActie uitvoert en dan de popup mc sluit.
              popup.popup_btn_ok_mc.btnLabel_txt.text = "O.K.";
              popup.popup_btn_ok_mc.onRelease = function() {
              trace("hiero");
              okAction.apply();
              popup.removeMovieClip();

              }
              }




              OUTPUT::

              onRelease: [type Function]
              j: 3
              i: 1
              onEnterFrame: [type Function]


              and also the trace "hiero" is reflected in thee output window.

              So, no okAction is found as a property of Tile102.
              I am puzzled.... Any suggestions??


              game.Tile102.prototype.klikAction = function(){
              • 4. Re: have a function perform a function
                kglad Adobe Community Professional & MVP
                use the attach code option to display code in this forum. otherwise, your code is difficult to read.

                is popup.popup_btn_ok_mc a member of the game.Tile102 class?
                • 5. have a function perform a function
                  spookmc Level 1
                  Ok, I'll use the attach from now, thanks

                  No, the popup is not a meber of the tile102 calss.

                  I create all tiles as classes, and I intend to use the popup wherever I like to.
                  It is convenient I think to create a popup, that can perform a parameter-specified function.
                  I am not a class specialist though...
                  • 6. Re: have a function perform a function
                    kglad Adobe Community Professional & MVP
                    okAction.apply() is being executed in the scope of popup.popup_btn_ok. so, if that's not a member of the game.Tile102 class, okAction() is not defined.

                    to remedy, you could use popup(tekst,this) in your klikAction method and use something like

                    function popup(tekst:String, tile:game.Tile102){

                    in your function definition and use

                    tile.okAction();

                    in your onRelease handler
                    • 7. have a function perform a function
                      spookmc Level 1
                      Hi kglad,

                      I am so happy that you continue in helping me. And I am happy that I succeeded in solving the issue.\
                      Problem is that i dynamically assign the game.Tilexxx.methods to clips.
                      I did not, however assign the okAction to the dynamicaaly created clips, assuming that they would be assigned by calling them in klikAction().

                      Thanks to your analysis I started seeing the real essence of my qquestion and managed to solve it.
                      Thanks! I am so happy!

                      Yours sincerely,

                      Martijn
                      • 8. Re: have a function perform a function
                        kglad Adobe Community Professional & MVP
                        you're welcome.