I made game using tutorial and now I want to extend it to have more levels, but when you lose in this game everything stays untouchable. I want to delete this monsters, delete towers and start everything again. Is there any way to delete all variables in Flash? I tried to open this scene again, but it's not working. Game link: http://tdarea.com/Bez%20nazwy-1.html
well it's hard to say without knowing more about your code structures - usually one would iterate through a storage array that contains references to the objects that have been instantiated and then use the [parent].removeChild( obj[i] ) method (pseudo code there)
so usually one creates a 'reset' method, right, that will go through and reset all the necessary properties to the defaults, removes objects, and gets it all set up as it was in the beginning
There's the project I used to create my game. There's downloadable source code so you can look there, it's very similar to mine. http://www.goofballgames.com/2010/01/31/building-a-flash-tower-defense-game-in-part-10-win-or-lose/
ok - well i haven't the time to read through the entire tutorial - however based on the comments there, others are having similar issues - i would bet that the makers of this tut will address the issue in future additions
i'd say that the extensive use of object attachment code and _root will make it very difficult to reset the game properly without major restructuring.
however, a quick hacky fix would be to trigger a call to getURL() that reloads the game page itself, thereby resetting the game to the original parameters.
@yorgi - the OP has followed the tutorial written at the site posted above. it is based in AS2 which you'll need some tools to construct - goggle Flash Game making
Beech, thanks for your help. I know it's a long time to read tutorial, here's the file with code, don't need to read whole tutorial. http://goofballgames.com/wp-content/themes/androida/Part10.zip
I was thinking about one option. What about level will be one swf file and the preloader will be the second one, when someone loses I will reload the external swf file which will be the same one. It's however not a good idea because the game will for sure spread into the Internet and will be loaded from another sites, so they will copy the swf file. Please help, look inside this zip file is the *.fla file, maybe this will tell you something.
ok I've taken a look at the game and it's code - quite honestly it's quite rough. although it 'works' it uses several methodologies that are known NOT to be *best practices*
- the extensive use of _root is entirely unnecessary particularly while it's already ON the main timeline (which resolves to _root)
- these declarations are not properly constructed, they are 'forcing' a property attachment on the Object (_root), correct property declarations look like this:
var propname:Number = 1.0;
NOT like this:
_root.propname = 1.0
- the use of 'Object attached' code all over the place, causes you to 'go hunting' for 'hidden code' on all instances in the game, this is *very* hard to debug/work with - in addition to causing path issues, and declarations of loose local properties
- the file came with a 'disclaimer' that said: (para) "your system might crash if you run this" - what? it's probably because they are continuing to add instances to the stage that EACH has it's own enterframe event, and probably isn't getting removed properly, this will stack the mem and eventually crash FP
- there is more, but i'm done picking this apart, it is simply bad code, and it's a shame that 'tutorials' are teaching these types of practices
---- in order to reset the game, you will have to go through and 1) reset each property in the game that is used everwhere 2) you'll have to kill any instances that have been propagated 3) restart the sequence handling
what you're talking about above is simply a more complex method of what i'd suggested, ie. reload the game - but you will have BIG problems if you place this in a preloader because every property is targeting _root <- which will target the preloader scope, and you'll run into path problems and null object references at every turn.
so my advice is to either, use the hack i've mentioned above, or port this project to a form is in-line with good programming techniques.
when you create something for one session place those things in Array(the best way too keep all variables and classes for deleting) and then using var = null or undefined(for movieclips use just delete fuction)
The best way for I 'll recommend is to understand how and what is created in this flash movie and then it's not a problem to restart your game
I have found nice thing. In function spawn which is responsible to create new "monsters" I created small "if function" which deletes each monster after the game is finished. Now I have to do the same with towers.
The code for deleting monster is very simple: if (_root.hasGameFinished) { this.removeMovieClip(); }