View Full Version : Exit(?) a class
mmorosky
August 1st, 2007, 11:03 AM
I've created a short game where the main class file, MainGame, creates an instance of the actual game, ActualGame. MainGame displays the start screen complete with a "Play game" button which creates an instance of ActualGame. After playing this game, I want the user to be able to end the game and go back to the MainGame screen. I am not sure how to somehow flag to the main class that I am done with the actual game.
I thought about including a loop in MainGame that checks a Boolean variable isPlaying that can be changed to false when the player wants to go back to the main menu.. There has to be a better way though.. Anyone?
GrndMasterFlash
August 1st, 2007, 11:46 AM
could you show use what script you are using to do this, that will help us help you:ne:
mmorosky
August 1st, 2007, 12:18 PM
Essentially what I have done is this..
Main class
-paints welcome message and "start" button
-when start button is pushed, paint is cleared, an instance of the game is created (e.g. var gameTest:Game = new Game();) and added with addChild.. The game plays just fine.
Game class
I've added a "quit" button to the screen.. when the user hits the quit button, however, I don't know what I could do to make it stop the current instance of GameClass and basically repaint the welcome screen.. I tried putting an event listener on the quit button from the MainClass that sets the instance of the game to null. (gameTest = null), but I get like 5 million of "TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Game/::onEnterFrame()" I'm guessing this is because the event listeners and so forth are still running in the instance. I need all of this stuff deleted with the class so that the program doesn't experience slowdown..
Any help would be greatly appreciated.. I'm hurtin' here.. :/
mmorosky
August 2nd, 2007, 09:10 AM
If I'm trying to essentially restart a movie, how can I do so with a button? Won't I have to delete all instances, variables, etc.? I have a lot of variables and arrays, and I don't know how I could manage to do this..
Krilnon
August 2nd, 2007, 11:30 AM
You could remove the old instance of ActualGame and create a new one. You could also have MainGame listen for an event that ActualGame dispatches upon game completion.
Charleh
August 2nd, 2007, 12:03 PM
Yeah dispatch events and have MainGame listen for them - it's the most efficient method for 'I'm a class waiting for something to happen in another class' scenarios
mmorosky
August 3rd, 2007, 07:59 AM
Okay, I'm not too sure what dispatch events are, but I'll look them up.
Thanks a lot for your help! :}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.