Withdrawal/reset timers for game

Greetings Flashdevelopers colleagues

My friend and I are trying to create a small Flash game for the school, but we're stuck trying to reset it when you have a Game Over.

The timers continue on the Game Over screen when you press the back button they continue to go to the menu screen as well.

We try to find a solution to the problem.

We also know how you made the game completely reset when you press the back button, so that you can start a new game with no problems.

package

{

import flash.display. *;

import flash.text.TextField;

import flash.utils.Timer;

import flash.events. *;

flash.ui import. *;

SerializableAttribute public class Main extends MovieClip

{

private var level: uint = 0;

private int var = 0;

private var: score: uint = 0

private var speed: uint = 10;

public void Main()

{

Stop();

}

public function verwijderObstacles (): void

{

If (getChildByName ("obstacle_mc")! = null) {}

mcObstacle (getChildByName ("obstacle_mc")) .destroy ();

}

}

public function verwijderPowerups (): void

{

If (getChildByName ("score_mc")! = null) {}

mcScore (getChildByName ("score_mc")) .destroy ();

}

}

public void initGame()

{

internship. Focus = stage;

var gravity: number = 3;

var jump: Boolean = false;

var jumpPower:Number = 0;

var score_mc:MovieClip = new mcScore();

var obstacle_mc:MovieClip = new mcObstacle();

If (!) Contains (score_mc))

{

var scoreTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

scoreTimer.addEventListener (TimerEvent.TIMER, spawnScore);

scoreTimer.start ();

}

If (!) Contains (obstacle_mc))

{

var obstacleTimer:Timer = new Timer (Math.ceil (Math.random () * 2) * 1000, 1);

obstacleTimer.addEventListener (TimerEvent.TIMER, spawnObstacle);

obstacleTimer.start ();

}

stage.addEventListener (Event.ENTER_FRAME, scrollBackground);

stage.addEventListener (Event.ENTER_FRAME, scrollClouds);

stage.addEventListener (KeyboardEvent.KEY_DOWN, jump);

stage.addEventListener (Event.ENTER_FRAME, update);

stage.addEventListener (Event.ENTER_FRAME, moveScore);

stage.addEventListener (Event.ENTER_FRAME, moveObstacle);

stage.addEventListener (Event.ENTER_FRAME, hitScore);

stage.addEventListener (Event.ENTER_FRAME, hitObstacle);

stage.addEventListener (Event.ENTER_FRAME, checkOverlap);

stage.addEventListener (Event.ENTER_FRAME, checkGame);

function scrollBackground(e:Event):void

{

If (!) (), getChildByName ("background1_mc") == null) & &! (getChildByName ("background2_mc") is nothing))

{

background1_mc.x = speed;

background2_mc.x = speed;

If (background1_mc.x < = - background1_mc.width)

{

background1_mc.x = background2_mc.x + background2_mc.width;

}

ElseIf (background2_mc.x < = - background2_mc.width)

{

background2_mc.x = background1_mc.x + background1_mc.width;

}

}

}

function scrollClouds(e:Event):void

{

If (!) (), getChildByName ("clouds1_mc") == null) & &! (getChildByName ("clouds2_mc") is nothing))

{

var cloudSpeed = speed / 5;

clouds1_mc.x = cloudSpeed;

clouds2_mc.x = cloudSpeed;

If (clouds1_mc.x < = - clouds1_mc.width)

{

clouds1_mc.x = clouds2_mc.x + clouds2_mc.width;

}

ElseIf (clouds2_mc.x < = - clouds2_mc.width)

{

clouds2_mc.x = clouds1_mc.x + clouds1_mc.width;

}

}

}

function jump(e:KeyboardEvent):void

{

if(e.keycode == Keyboard.Space)

{

If (jump! = true)

{

jumpPower = - 30;

jumping = true;

player_mc.gotoAndPlay (46);

}

}

}

function update(e:Event):void

{

If (Jumping)

{

player_mc.y += jumpPower;

jumpPower += gravity;

If (player_mc.y > = 320)

{

jumping = false;

player_mc.y = 320;

player_mc.gotoAndPlay (61);

}

}

}

function spawnScore(e:TimerEvent):void

{

var randomNumber:Number = Math.round (Math.random ());

addChild (score_mc);

score_mc. Name = "score_mc";

if(randomNumber == 0)

{

score_mc.x = 800;

score_mc.y = 240;

}

on the other

{

score_mc.x = 800;

score_mc.y = 30;

}

}

function spawnObstacle(e:TimerEvent):void

{

addChild (obstacle_mc);

obstacle_mc.x = 800;

obstacle_mc.y = 240;

obstacle_mc. Name = "obstacle_mc";

}

function moveScore(e:Event):void

{

score_mc.x = speed;

If (!) (), getChildByName ("score_mc") is nothing))

{

If (score_mc.x <-86)

{

removeChild (getChildByName ("score_mc"));

var scoreTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

scoreTimer.addEventListener (TimerEvent.TIMER, spawnScore);

scoreTimer.start ();

}

}

}

function moveObstacle(e:Event):void

{

obstacle_mc.x = speed;

If (!) (), getChildByName ("obstacle_mc") is nothing))

{

If (obstacle_mc.x <-72)

{

removeChild (getChildByName ("obstacle_mc"));

var obstacleTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

obstacleTimer.addEventListener (TimerEvent.TIMER, spawnObstacle);

obstacleTimer.start ();

}

}

}

function hitScore(e:Event):void

{

If (!) (), getChildByName ("score_mc") == null) & &! (getChildByName ("player_mc") is nothing))

{

If (player_mc.hitTestObject (score_mc))

{

removeChild (getChildByName ("score_mc"));

var scoreTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

scoreTimer.addEventListener (TimerEvent.TIMER, spawnScore);

scoreTimer.start ();

player_mc.gotoAndPlay (2);

Note ++;

if(score == 1)

{

gauge_mc.gotoAndPlay (2);

}

another if (score == 2)

{

gauge_mc.gotoAndPlay (16);

}

Another yew (score is 3)

{

gauge_mc.gotoAndPlay (31);

}

Another yew (score is 4)

{

gauge_mc.gotoAndPlay (46);

}

another if (score == 5)

{

gauge_mc.gotoAndPlay (61);

}

}

}

}

function hitObstacle(e:Event):void

{

If (!) (), getChildByName ("obstacle_mc") == null) & &! (getChildByName ("player_mc") is nothing))

{

If (player_mc.hitTestPoint (obstacle_mc.x, obstacle_mc.y, true))

{

removeChild (getChildByName ("obstacle_mc"));

var obstacleTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

obstacleTimer.addEventListener (TimerEvent.TIMER, spawnObstacle);

obstacleTimer.start ();

player_mc.gotoAndPlay (16);

-life;

lives_txt. Text = 'x' + lives.toString ();

}

}

}

function checkOverlap(e:Event):void

{

If (obstacle_mc.hitTestObject (score_mc))

{

If (!) (), getChildByName ("score_mc") is nothing))

{

removeChild (getChildByName ("score_mc"));

var scoreTimer:Timer = new Timer (Math.ceil (Math.random () * 5) * 1000, 1);

scoreTimer.addEventListener (TimerEvent.TIMER, spawnScore);

scoreTimer.start ();

}

}

}

function checkGame(e:Event):void

{

If (Lives < 0)

{

scoreTimer.stop ();

obstacleTimer.stop ();

If (getChildByName ("score_mc")! = null) {}

mcScore (getChildByName ("score_mc")) .destroy ();

}

gotoAndStop ("gameover");

}

}

}

}

}

It is the AS3 script that we wrote for the game. I pointed out the places in red where we tried to write the code for the Game Over screen.

You have a lot of listeners ENTER_FRAME events at work, at least one of them is indicative of the timer with start().  You have to remove if you want to start and stop Timers.

Tags: Adobe Animate

Similar Questions

  • How to reset many Solitaire games played and won Matches of the counters?

    How to reset many Solitaire games played and won Matches of the counters?

    Hi Keith,

    Found an answer for Vista, that should work for you in Windows 7.

    To reset the game statistics, you must delete some files. These files will be re-created automatically the next time you play the game. The files are located in the following location: 'C:\Users\[UserName]\AppData\Local\Microsoft Games\ [game]", where [username] is the name of your account and [game] is the name of the game (in your case, Solitaire). Just delete the contents of the folder, but DO NOT delete the folder itself.

    http://www.Vistax64.com/gaming/139902-Solitaire-statistics-reset.html

  • My iPhone4 is disabled permanently and will not restore on iTunes. Is there something I can do? (This phone is used for games for my children).

    iPhone4 used for games is disabled permanently. Not restore on iTunes.

    What is the message you get from iTunes when you try to restore it?

  • This laptop is good for games like WoW or the Sims 3?

    I want to get a new laptop around the mark of $400 - $800 or less may be possible (but I doubt it) that can operate computer games and is good for other things.

    Does anyone know a good laptop, I could get?

    Hello

    If you want to use the laptop for games, I recommend buying one with an external graphics card. Means the graphics card should not be a part on Intel CPU (Intel HD GPU) but you must choose the laptop with a chip graphic ATI or nVidia GPU.

    See the Toshiba product page for more details on laptops equipped with such GPU

  • HP probook 440 g2: rom bios reset password for hp probook 440 g2

    I am in urgent need to reset password for the bios rom for my g2 440 probook. It has been days and I'm still stuck on the same screen.

    Hello

    Unfortunately, business machines such as Probooks or EliteBook have more strict security consumption patterns - they do not produce "stop codes", the password cannot be derived from the serial number and the code is stored in a nonvolatile memory to remove the RTC cell does not reset the password in this case.

    If you Contact HP Business support they should be able to send you a file custom SMC.bin that you can use to reset the password at startup.

    Kind regards

    DP - K

  • How to use my gift card money in itunes for games

    How use the currency for games iTunes gift cards, in particular, game of Thrones ascent, which I play on my iPad Air through FaceBook, but also windows platform uses. ?   Does anyone know how to do this?

    You can use the balance of your iTunes make in-app purchases in the game in the iTunes App Store on your iPad, and through this iTunes account - you can not use your iTunes account to make purchases on windows or on Facebook.

  • I want to buy a better graphics card for games - what graphics cards are compatible with my pc

    I need help on graphics cards is compatible with the motherboard in my PC...

    I need a better graphics card, one for games with 2 GB of video ram. Need help choosing a graphics card on my PC.

    PC name: Pavilion Slimeline s5730y

    Hello

    Yes. and Yes.

    The issue of power supply is theoretical, as, once again, is not necessary to insert a graphics card on the system board.

    You have zero options to upgrade graphics card.

    Jay

  • HP PAVILION 17-F061NB: for games cooling pad?

    Right then, the story made short: I recently (a few months), bought a HP Pavilion 17-F061NB computer laptop computer laptop, which I use mainly for games. It has a processor AMD A10, with 12 GB of ram, and and AMD Radeon R7 M260 dedicated graphics card. Shortly after I bought it, (first day), in fact, I felt that the laptop has been hot all game, sometimes even simply watching videos.  (I'm playing minecraft, life is feudal: your own, battle field 4 (a little)).  So recently I've been thinking, it would help if I bought a GOOD laptop cooling pad? I use my laptop on my desk, not on my knees. I don't have any tips/advice on the cooling pad, I can understand that for my part, I'm just curious if these things help you or not.

    URGENT PLEASE RESPOND QUICKLY;-

    @JonasIsTheName

    Welcome to the Community Forum of HP.

    Comment

    I have two of the coolers below; I was happy with the performance.   They have been used to cool HP dv7t 17 "computers laptops running 8 GB of RAM, Intel switchable graphics card.

    I do not 'game'; I'm doing some work that pushes the graphics system and the memory of Photo editing.  Photo editing is not the same thing as the game; former dv17t model HP notebooks run hot, so there may be some use for the comparison.

    Option: Connect the laptop cooler to a Powered Hub from Siig.  The cooler provides its own on/off switch, which allows you to turn it off when you don't need it or when you are finished using the system.  Of course, don't forget to turn off the radiator when you connect the cooler to an arrangement of external hub.

    Zalman ZM-NX2000 Notebook Cooler

    There are other models of Zalman's model family.

    I suggest that you add the Zalman ZM-NX2000 to your list of "considerations", that you take a look at other offers.

    For example:

    Review of chillers portable 2015

    You can check sites like "NewEgg.com" and other retailers that sell laptop coolers and see what people are saying on their purchases.

    When you see a post that will help you,

    Who inspires you, gives a cool idea,

    Or you learn something new.

    Click the 'Thumbs Up' on this post.

    My answer-click accept as Solution to help others find answers.

  • Pavilion 500-270: looking to get a new processor for games

    I'm looking to upgrade my processor for games. I currently have:

    CPU: Intel Core i3 4130 (dual-core) synchronizing to 3.5 GHz (socket LGA 1150)

    Mobo:HP 2AF7, Intel Haswell H87 Chipset rev 06

    8 GB RAM

    Graphics card Intel HD Graphics 4400, but also a NVIDIA Geforce 3900 GS graphics card

    Is there any particular processor (preferably less $ 200) which would be good for gaming?

    Please let me know what you recommend.

    Thank you

    Hello

    Review the processors that are updated approved for HP 500-270.

    I suggest that you consider using a discrete graphics card before the upgrade of the processor.

    Consult this publication of the article.

    The NVIDIA GTX 750 graphics card would be a good choice for the games with high settiings game support.  Looking for a 750 that does not require a power supply connector 6-pin PCI-E auxiliary.

    HP Secure Boot Windows 8 themes Computer does not start after the installation of a video (Windows 8) card  

    These articles HOWTO HP should be useful.

    If you are in the high-end gaming then the cost will be closer to $400.

  • AMD A6 Series: How to speed up my laptop for games

    Product number: How can J5t41UA #ABA I speed up my laptop without losing too much money?

    Andres2

    To provide a little explanation, there is really little of anything you can do with a laptop.

    To speed up your desktop for games, you could consider all the following:

    (1) upgrade the current processor to a more powerful and faster that remains compatible with the motherboard

    2) install faster memory - if it is available and if the motherboard will handle it.  If the faster memory is not available, then the current memory overclock (and if necessary, the CPU as well)

    (3) install more memory - if you use very little, say 1 GB

    (4) replace the integrated graphic card graphics high-end focus on the game - which will be VERY expensive!

    (5) replace the hard drive with one of the new, high-end SSD

    In a laptop, you can often add more memory, but not enough to actually help gaming performance; and also, you can replace the hard drive with an SSD.  But even in this case, comparative tests have shown that game by using an SSD does not result in the improvement of the notable performance during the game with a hard drive at high speed.

    So, basically, no, there is really nothing you can do to turn your laptop into a game machine.

    Sorry

  • looking for games for windows 7 that are compatible with xbox wired controller. Games must work more precisely on the pc, as I don't have a system like the ps3 or xbox. Thank you.

    video games

    Hello

    You can search using your favorite search engine of games that are compatible with Windows 7. Also check the link given below for Games for Windows.

    http://www.Microsoft.com/games/en-us/games/pages/Catalog1.aspx

    Amrita M

    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Upgrades for games

    Hello

    I was wondering what updates (if there is one) I can do for my laptop. The model is a PC HP Pavilion laptop g6-1210sa. It is running on windows 7, it has a 600 GB HDD and 6 GB of ram, so these components are all very well. I really wonder on the graphics card, processor, motherboard, etc.

    As I said in the topic sound for games. If theres anythin another thing which you need, the system BIOS or such just posting a reply and I'll put all this. Thanks for the help.

    -Darren

    Dazo52 wrote:

    Are there any upgrade, I can get to the integrated graphics card?

    Graphics chips for this type of laptop computers are soldered to the motherboard. The only way how to change is to replace the motherboard with a compatible one equipped with a more powerful chip. See the manual.

  • Format my old pc with windows xp prof for games

    I would like to format my old pc with legal copy of windows xp prof and maintain your pc for games and old files

    Kindly let me know if I can get the updates before April 8, 2014.

    Hello HKaurND,

    All updates before April 8, 2014 will be always available for download via the Windows updates if you decide to reinstall Windows XP. Thanks to Microsoft to no longer support XP after April 8 you'd be advised to upgrade to a newer version of Windows, i.e. Windows 7/8.1

    This forum post is my own opinion and does not necessarily reflect the opinion or the opinion of Microsoft, its employees or other MVPS.

    John Barnett MVP: Windows XP Expert associated with: Windows Expert - consumer: www.winuser.co.uk | vistasupport.mvps.org | xphelpandsupport.mvps.org | www.silversurfer-Guide.com

  • Adapter for games with switches

    I wonder if I use a games linksys adapter to connect my PS3 to wireless internet, if I can just drop a switch and hook my two HDDVR and PS3 to wireless internet? The adapter for games will be an IP address for the two devices are connected to the switch?

    You can connect a game adapter to one of the devices, the adapter for games will not pull an IP address for both the devices connected to the switch...

  • How to change Windows base score to 3.3 for games

    I place my base score 3.2 experience dated now I can't until he grade level according to 3.3 for games
    so I'll try to find a download for the base score so I won't have to pay for windows 7, or something to get what I want
    I have windows vista 32 bit, I hope you can help

    Please read:

    http://Windows.Microsoft.com/en-AU/Windows-Vista/what-is-the-Windows-experience-index

    ..... Windows Experience Index measures the capability of the hardware and software of your computer configuration and expresses this measurement as a number called a base score. ......

    You need to upgrade your hardware if you want a higher base score.

Maybe you are looking for