Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:59:36+00:00 2026-05-26T20:59:36+00:00

I have many functions ( funcOne, funcTwo, etc. ), all of them share the

  • 0

I have many functions (funcOne, funcTwo, etc.), all of them share the same block of checks at the beginning (I want to move those blocks to a separate function or something so I’m not repeating code, but the problem is that I use return. Please read on)

  • If any of these checks fail, I output a specific message that this specific check failed, and return (so the actual code of the function doesn’t execute)
  • If all checks pass, the function continues to the specific code of the function.

What I want to do is move those checks to a separate function. But the problem is that I’m using return; which would return out of the new function, but wouldn’t return from funcOne and funcTwo. Can someone help me refactor this code so I don’t have to repeat the duplicate checks in every function that uses them.

protected function funcOne(event:MouseEvent):void
{
   if( check 1 doesn't pass){
      Alert.show("error 1, returning);
      return;
   }
   if( check 2 doesn't pass){
      Alert.show("error 2, returning);
      return;
   }
   .... more checks here, all of them return specific messages 

   //if all checks pass
   //execute the specific code of this funcOne
}
protected function funcTwo(event:MouseEvent):void
{
   if( check 1 doesn't pass){
      Alert.show("error 1, returning);
      return;
   }
   if( check 2 doesn't pass){
      Alert.show("error 2, returning);
      return;
   }
   .... more checks here, all of them return specific messages 

   //if all checks pass
   //execute the specific code of this funcTwo
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:59:37+00:00Added an answer on May 26, 2026 at 8:59 pm

    Here’s a quick way to do it. You could also return the actual message string if you want to handle the alert elsewhere. If the message string is null, then there’s no error.

    protected function funcOne(event:MouseEvent):void
    {
        if(validate())
        {
            //if all checks pass
            //execute the specific code of this funcOne
        }
    }
    
    protected function funcTwo(event:MouseEvent):void
    {
        if(validate())
        {
            //if all checks pass
            //execute the specific code of this funcOne
        }  
    }
    
    //returns false if not valid
    protected function validate():Boolean
    {
        var errorMessage:String = null;
    
        if( check 1 doesn't pass)
            errorMessage = "error 1, returning";
        else if( check 2 doesn't pass)
            errorMessage = "error 2, returning";
    
        if(errorMessage)
            Alert.show(errorMessage);
    
        return !errorMessage as Boolean; //will return true if errorMessage is null
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have many C functions of the same signatures and we want to
I have many PHP files in / /client/ /user/ /config/ etc... I want all
I have a js variable with many functions, and I want to create in
I have many functions of the same long signature (shortened here for simplicity): (defn
Is it bad to have too many self-invoking functions in JavaScript? If they all
In my interface, I will have many functions. All of these will be binded
I have many functions like updateUser($id,$username,$email) updateMusic($id, $music) etc... Is there a generic function
I have many functions written in JavaScript such as userName() , password() etc. But
I have many structs (classes) and standalone functions that I like to compile separately
I have a c++ program which has many many functions and I have different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.