Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

flash and php score refresh

Guest
Dec 06, 2010 Dec 06, 2010

Hi there, I'm wondering if anyone can help me with this php scoreboard.. our developers aren't being very helpful...

So problem is the score board is shown at the beginning if requested and at the end to show your score when the game is finished. The problem I have is refreshing the scores (replacing the current text in the boxes) rather than just adding the text again into the dynamic text boxes..

Here is my code :-

var tab = "game1score";// update for each game // game2score, game3score....

var filesend = "receive.php";

var modesend = "post";

//This is called when the high scores are viewed at the beginning of the game

private function onHighScoresButtonClick(event:MouseEvent):void {
           
     var receptobjet = variableTransaction(filesend, modesend, tab, false, false);
     highScoresPage.rejouerButton.visible = false;
     highScoresPage.blueMan.visible = false;
     removeChildAt(0);
     addChildAt(highScoresPage, 0);
}

function variableTransaction(fichier, modesend, tab, var1, var2) {
   
     var URLload = new URLLoader();
     var URLrequest = new URLRequest(fichier);
     var variables:URLVariables = new URLVariables();
   
     variables.tab = tab;
     variables.var1 = var1;
     variables.var2 = var2;

     if (modesend == "post") {
          URLrequest.method = URLRequestMethod.POST;
          } else if ( modesend == 'get') {
               URLrequest.method = URLRequestMethod.GET;
          }
   
           if (var1 == false && var2 == false) {
       
               URLload.dataFormat = URLLoaderDataFormat.VARIABLES;
               URLrequest.data = variables;
               URLload.load(URLrequest);

               URLload.addEventListener(Event.COMPLETE, modeComplet, false, 0, true);
            } else {
                URLrequest.data = variables;
                URLload.load(URLrequest);
       
                //var receptobjet = variableTransaction(filesend, modesend, tab, false, false);
            }

     }

function modeComplet(event:Event) {
           
            for (var p:uint = 1; p <= 10; p++) {
               
                var currentPseudo:String = "pseudo" + p;
                var currentScore:String = "score" + p;

                if (event.target.data["pseudo" + p]) {
                    highScoresPage[currentPseudo].appendText(event.target.data["pseudo"+p]);
                    if (event.target.data["score" + p]) {
                        highScoresPage[currentScore].appendText(event.target.data["score"+p]);
                    } else {
                        highScoresPage[currentPseudo].appendText(" \n");
                        highScoresPage[currentScore].appendText(" \n");
                    }
                }
            }
        }

        private function gameEnd(event:Event):void {
           
            var pseudo = highScoresPage.pseudo0.text;
            var score = highScoresPage.score0.text;

            var filesend = "send.php";
            var modesend = "post";

            variableTransaction(filesend, modesend, tab, pseudo, score);
           
            var persoArray:Array = [gamePage.a1, gamePage.a2, gamePage.a3, gamePage.a4, gamePage.a5];
            var animalArray:Array = [gamePage.b1, gamePage.b2, gamePage.b3, gamePage.b4, gamePage.b5];
            var persoHitArray:Array = [gamePage.h1, gamePage.h2, gamePage.h3, gamePage.h4, gamePage.h5];
            var animalHitArray:Array = [gamePage.h6, gamePage.h7, gamePage.h8, gamePage.h9, gamePage.h10];           
            for(var i:uint = 0; i < persoArray.length; i++) {
                (persoArray).removeEventListener(MouseEvent.MOUSE_DOWN,persoMouseDown);
                (persoArray).removeEventListener(MouseEvent.MOUSE_UP,persoMouseUp);
                (persoArray).buttonMode = false;
            }
            for(var j:uint = 0; j < persoArray.length; j++) {
                (animalArray).removeEventListener(MouseEvent.MOUSE_DOWN,animalMouseDown);
                (animalArray).removeEventListener(MouseEvent.MOUSE_UP,animalMouseUp);
                (animalArray).buttonMode = false;
            }
            for(var k:uint = 0; k < persoHitArray.length; k++) {
                (persoHitArray).visible = true;
            }
            for(var l:uint = 0; l < animalHitArray.length; l++) {
                (animalHitArray).visible = true;
            }
           
            buttons.rulesButton.removeEventListener(MouseEvent.CLICK,onRulesButtonClick);
            buttons.startGameButton.removeEventListener(MouseEvent.CLICK,onStartGameButtonClick);
            buttons.highScoresButton.removeEventListener(MouseEvent.CLICK,onHighScoresButtonClick);
            buttons.infoButton.removeEventListener(MouseEvent.CLICK,onInfoButtonClick);
            //completePage.linkButton.removeEventListener(MouseEvent.CLICK,onLinkButtonClick);
            mainTimer.removeEventListener(TimerEvent.TIMER,incrementCounter);
           
            countdownTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,levelEnd);
           
            //countdownTimerEnd.removeEventListener(TimerEvent.TIMER_COMPLETE,gameEnd);
            //highScoresPage.rejouerButton.removeEventListener(MouseEvent.CLICK,onRejouerButtonClick);
            psuedoPage.goButton.removeEventListener(MouseEvent.CLICK,onGoButtonClick);
           
            gamePage = null;
           
            removeChildAt(0);
            addChildAt(highScoresPage, 0);
           
            highScoresPage.rejouerButton.visible = true;
            highScoresPage.blueMan.visible = true;
           
        }

TOPICS
ActionScript
880
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 06, 2010 Dec 06, 2010

what do you mean by, "Each time I go onto the highscores page"?   does that occur when you click the highscores button?

Translate
Community Expert ,
Dec 06, 2010 Dec 06, 2010

i see some highscore code.  it would only make sense to display that at the start and update and display at the end.  what is it that you want to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 06, 2010 Dec 06, 2010

Each time I go onto the highscores page, I would like the high scores to REFRESH rather than the text being added to the each box twice or however many times I return to the page

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 06, 2010 Dec 06, 2010

I see what you mean by updating and displaying at the end.. that would work just

as well but if I set the boxes to "", the same thing happens ^^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2010 Dec 06, 2010

what do you mean by, "Each time I go onto the highscores page"?   does that occur when you click the highscores button?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 06, 2010 Dec 06, 2010

it does. I also want the scores to be updated just after the end of the game

before the scores are displayed so the player can see their score if they get a high score

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 06, 2010 Dec 06, 2010

I think the problem lies in the var in the last } else { statement below. I originally had this commented out because of the problem.

On sending the variables to be added to the database it requests the scores again, but instead of 'refreshing' (i.e removing the old scores and replacing them with the updated scores) it is sending another request and just adding to the scores already in the boxes...

Please don't hesitate to tell me if I'm not clear !

function variableTransaction(fichier, modesend, tab, var1, var2) {
   
            var URLload = new URLLoader();
            var URLrequest = new URLRequest(fichier);
            var variables:URLVariables = new URLVariables();
   
            variables.tab = tab;
            variables.var1 = var1;
            variables.var2 = var2;

            if (modesend == "post") {
                URLrequest.method = URLRequestMethod.POST;
            } else if ( modesend == 'get') {
                URLrequest.method = URLRequestMethod.GET;
            }
   
            if (var1 == false && var2 == false) {
       
                URLload.dataFormat = URLLoaderDataFormat.VARIABLES;
                URLrequest.data = variables;
                URLload.load(URLrequest);

                URLload.addEventListener(Event.COMPLETE, modeComplet, false, 0, true);
            } else {
                URLrequest.data = variables;
                URLload.load(URLrequest);
       
                var receptobjet = variableTransaction(filesend, modesend, tab, false, false);
            }
        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2010 Dec 06, 2010
LATEST

use the following if you don't want anything appended to your textfields.  i can't tell what that will look like but here's how you would do it:

function modeComplet(event:Event) {
           
            for (var p:uint = 1; p <= 10; p++) {
               
                var currentPseudo:String = "pseudo" + p;
                var currentScore:String = "score" + p;

                if (event.target.data["pseudo" + p]) {
                    highScoresPage[currentPseudo].text=event.target.data["pseudo"+p ];
                    if (event.target.data["score" + p]) {
                        highScoresPage[currentScore].text=event.target.data["score"+p];
                    } else {
                        highScoresPage[currentPseudo].text=" \n";
                        highScoresPage[currentScore].text" \n";
                    }
                }
            }
        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines