-
Useless Code
In my project im working on i have quite a few if and else statements that only need to be checked while its false and then one true it wont ever change. Is there a way to make flash stop checking code or even delete code when its not needed?
EG:
if ((FirstRun == false) and (i>=24)) {
FirstRun = true;
}
This is just an example, but when FirstRun = true its not ever going to be changed but flash is still going to check if ((FirstRun == false) and (i>=24)), can i stop this from happening, can you delete functions at runtime?
-
You can delete functions:
Code:
function myFunction() { };
delete myFunction;
I think that will destroy the reference in memory to the function. But then flash will be calling a variable to no where, that might not be so good.
So why do you run code once (after so many frames from the look of things), is this for an enemy attack pattern or something? Surely a better way there is.
-
have your code running on one frame or to then move to another frame with the same stuff except the piece of code you wanna drop
-
eeeewww ;)
Try using function pointers, eg
Code:
myFunc=firstTimeCheck;
function firstTimeCheck(){
//Do the check that'll only happen once.
//Check is true ?
myFunc=noCheck;
//else
noCheck();
}
function noCheck(){
//Main body of code you wish to run
}
Then on your enterFrame just add
Function pointers are such a God send. I'm actually coding a game name which let's you guide customers around a shopping mall ( Kinda Puzzled Sheep / Lemmings style ) and the people class is just a huge collection of functions, and I just change the pointers when they need to do different things ( Like get in a lift, enter a shop etc. ).
Squize.
-
I agree.. once you go function pointers, you never go back. ;)