Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:10:24+00:00 2026-05-31T13:10:24+00:00

I have a memory game program and when the timer runs out, I want

  • 0

I have a memory game program and when the timer runs out, I want it to go to frame 3 where it displays the “game failed” page.

I have it all set up, except when the game runs out of time, the frame just appears to overlap the original frame, instead of going to a completely separate page.

Can anyone help me?

Here is my code:

package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.text.TextField;

public class MemoryGame extends MovieClip{

    private var firstTile:cards;
    private var secondTile:cards;
    private var pauseTimer:Timer;
    private var score:int;
    private var cardCount:int;
    var seconds:Number;
    var minutes:Number;


    var numberDeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6);


    public function MemoryGame(){

        //TIMER FUNCTION
        var levelTimer:Timer = new Timer(1000, 180);
        levelTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
        levelTimer.addEventListener(TimerEvent.TIMER, timerHandler);

        // LEVEL FUNCTION
        easyBtn.addEventListener(MouseEvent.CLICK, easyButtonClicked);
        medBtn.addEventListener(MouseEvent.CLICK, medButtonClicked);
        hardBtn.addEventListener(MouseEvent.CLICK, hardButtonClicked);

        score = 0;
        txtScore.text=""+score;

        //Level button events
        function easyButtonClicked(e:MouseEvent):void{
            removeChild(levelText);
            trace("easy button clicked!");
            seconds = 0;
            minutes = 1;
            txtTime.text = "1:00";
            levelTimer.start();
            setupTiles();
        }

        function medButtonClicked(e:MouseEvent):void{
            removeChild(levelText);
            trace("medium button clicked!");
            seconds = 30;
            minutes = 0;
            txtTime.text = "0:30";
            levelTimer.start();
            setupTiles();
        }

        function hardButtonClicked(e:MouseEvent):void{
            removeChild(levelText);
            trace("hard button clicked!");
            seconds = 15;
            minutes = 0;
            txtTime.text = "0:15";
            levelTimer.start();
            setupTiles();
        }


        //Timer handlers
        function timerHandler(e:TimerEvent):void {
            if (seconds > 00) {
            seconds -=1;
            }

            else {
                if (minutes > 0) {minutes -=1;seconds = 59;}
        }
                txtTime.text = minutes+":"+(seconds >= 10 ? seconds : "0"+seconds);
            }

        function timerCompleteHandler(e:TimerEvent):void {
            e.target.reset();
            e.target.stop();
            trace("game over!");
        }



        //Tiles set up
        function setupTiles(){
        for(x=1; x<=4; x++) {
            for (y=1; y<=3; y++){
                var randomCard = Math.floor(Math.random()*numberDeck.length);
                var tile:cards = new cards();
                tile.card = numberDeck[randomCard];
                numberDeck.splice(randomCard,1);
                tile.gotoAndStop(9);
                tile.x = (x-1) * 150;
                tile.y = (y-1) * 200;
                tile.addEventListener(MouseEvent.CLICK,tileClicked);
                addChild(tile);
                cardCount = cardCount + 1
            }
        }
    }
    }




    public function tileClicked(event:MouseEvent) {
        var clicked:cards = (event.currentTarget as cards);
        if (firstTile == null){
            firstTile = clicked;
            firstTile.gotoAndStop(clicked.card);
        }
        else if (secondTile == null && firstTile != clicked){
            secondTile = clicked;
            secondTile.gotoAndStop(clicked.card);
            if (firstTile.card == secondTile.card){
                pauseTimer = new Timer(1000, 1);
                pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
                pauseTimer.start();

            }
            else {
                pauseTimer = new Timer(1000, 1);
                pauseTimer.addEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
                pauseTimer.start();
            }
        }

        if (seconds == 0){
            this.gotoAndStop(2);
            pauseTimer.stop();
            //levelTimer.stop();
        }
    }


    public function resetCards(event:TimerEvent) {
        firstTile.gotoAndStop(9);
        secondTile.gotoAndStop(9);
        firstTile = null;
        secondTile = null;
        pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,resetCards);
        score = score - 2;
        txtScore.text=""+score;
    }


    public function removeCards(event:TimerEvent){
        removeChild(firstTile);
        removeChild(secondTile);
        firstTile = null;
        secondTile = null;
        pauseTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,removeCards);
        score = score + 10;
        txtScore.text=""+score;
        cardCount = cardCount - 2;
        trace("Cardcount: " + cardCount);

        if (cardCount == 0){
            this.gotoAndStop(2);
            txtFinalScore.text=" "+score;
            pauseTimer.stop();          
            }
                }
}   
}

Thank you so much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:10:24+00:00Added an answer on May 31, 2026 at 1:10 pm

    When you add an object using addChild(object) it isn’t associated with keyframes along the timeline.

    So what you need to do is rather than jumping to frame 2, removeChild(object) or object.visible = false all children you don’t want and addChild(object) your ‘out of time’ assets.

    A good work ethic is to create destroy() functions that remove and null any unwanted assets. This way you can easily remove unwanted items and free up memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a memory game here. And each time a card is removed from
Say I'd like to make a memory/pairs game. I have currently made a draft
I have source code for a project that inspects a game's memory values. The
For my assignment I have to put make a card memory game that allows
Im writing this childrens game (memory) and have a list of tiles (List) which
i'm about to developp a memory game for children like ,i have 6 different
I am developing a memory game, in which I want to play background music
I'm making a small game engine and need to have a memory pool associated
Im learning Java and Im creating a memory type game where you have to
ok well i have a simple game that uses really high of memory and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.