Replay button in drag drop game
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Replay button in drag drop game

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    Replay button in drag drop game

    Can someone help me with the code for a replay button in a drag and drop game. Need it to appear when game has successfully been completed.
    Or just on screen thu entire game is fine too.

    It's just a 1 frame flash movie since all the components are movie symbols.

    Well while I'm asking can anyone help me add sound - I need a sound to play if they choose wrong and a different sound to play if they choose correctly.

    Thanks!!

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    How on earth can we help you if you haven't provided your FLA file o.O? It's not like every Drag 'n' Drop game is made in the same way as yours, lolz :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    Here is the fla

    Sorry - so new to all this I am ignorant of protocol.
    Thanks for letting me know. And here it is.

    Shoot it's too big! Now what? OK here is a link to download it:
    http://www.hummingbirded.com/parking-cars.fla.zip

    Thanks!

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Oh, you've programmed the game in a way which it's harder to add a replay button. I am just going to use this code (even though it's not the best, but better than you having to edit every single car's code in order to implement the replay button), code goes on your Frame:

    Actionscript Code:
    function checkReplay(){
        onEnterFrame = function(){
            i = 0;
            for(a=1;a<11;a++){
                if(_root["blankresponse"+a+"_mc"]._currentframe == 2){
                    i++;
                }
            }
            if(i == 10){
                replay_mc.gotoAndStop(2);
                delete onEnterFrame;
            }
        }
    }

    checkReplay();

    We create a function, which will start an onEnterFrame loop, which will continuously execute the codes inside it, until we delete it. In this onEnterFrame loop, we create a new variable, i, with the starting value as 0. Then it will check how many smiley movieclips are on Frame 2, where they are visible, and for every visible smiley, variable i will be incremented by one. If variable i is equals to 10, after all the smileys have been checked, then it means that all the cars are on their target, and then we can make replay button visible, and delete the onEnterFrame loop for executing any further codes, but if variable i is NOT equals to 10, then all of the codes will be executed again, making variable i's value 0, and increasing it for how many smiley's are visible!

    Then make a new layer in your Flash file, on top of all the layers, and draw a replay button. Convert that replay button to a Movieclip, give it an instance name of, replay_mc, and enter that movieclip, and create a new frame on Frame 2, and have your button there, while Frame 1 is empty, and on Frame 1, type, stop();. Create a new layer at the bottom, below the button (which should also be empty on Frame 1), and draw a huge rectangle, covering the whole screen, convert it to a button, and give it an instance name of, my_btn. Then, press on this button, open Properties Panel and turn down its Alpha (if you want the game below to be half-seen). After that, click on your Frame (while still being inside the replay_mc movieclip), open Actions Panel and type this:

    Actionscript Code:
    my_btn.useHandCursor = false;

    This will block the cars from being draggable while the replay movieclip is visible (by creating a button over them, which doesn't change the cursor to a hand when on roll over).

    Next, get out of replay movieclip, give each one of your cars, an instance name like, starting from the first one, car1, car2, car3, etc; and on your Frame actions, after the function we wrote earlier, type this:

    Actionscript Code:
    for(c=1;c<11;c++){
        _root["car"+c].originalX = _root["car"+c]._x;
        _root["car"+c].originalY = _root["car"+c]._y;
    }

    This will save the original coordinates of the cars in their own movieclips, since you did it in a way which made it hard to accomplish this without having lots and lots of unnecessary code.

    Then, enter back inside replay movieclip, click on your replay button, open Actions Panel, and type this:

    Actionscript Code:
    on(release){
        for(i=1;i<11;i++){
            _root["car"+i]._x = _root["car"+i].originalX;
            _root["car"+i]._y = _root["car"+i].originalY;
            _root["blankresponse"+i+"_mc"].gotoAndStop(1);
        }
        _root.checkReplay();
        gotoAndStop(1);
    }

    This will reset the cars' position and turn the smileys back to invisible. Moreover, we will start the onEnterFrame loop again to check for all the smileys being on Frame 2, and then we turn the replay movieclip back to invisible by going to Frame 1.

    Sorry, but this was the easiest way I found for you, because you coded this in a very odd and messy way, so it was much harder to implement this replay function to your game.

    Nonetheless, hope this helps

    PS: Don't bother turning the smileys to gray, just remove the gray circle on their first frame, 'cause it will work either way, and will look better this way

    DOWNLOAD FLA FILE
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thank yyou so much!!!

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    no problem, happy to help
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center