A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Useless Code

  1. #1
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874

    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?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  2. #2
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    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.

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    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
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  4. #4
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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
    Code:
    myFunc();
    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.

  5. #5
    Patron Saint of Beatings WilloughbyJackson's Avatar
    Join Date
    Nov 2000
    Location
    Ro-cha-cha-cha, New York
    Posts
    1,988
    I agree.. once you go function pointers, you never go back.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center