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 6961633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:33:22+00:00 2026-05-27T15:33:22+00:00

say there is a class package { public MyClass { var myA:Number = 10

  • 0

say there is a class

package
{

 public MyClass 
 {

   var myA:Number = 10 ; //<< initializing here 

     public function MyClass()
     {
        myA = 20; //<< initializing here
     }

 }

}

Which one of the above is the right way to follow ?

  • 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-27T15:33:22+00:00Added an answer on May 27, 2026 at 3:33 pm

    At a conference I attended, I was advised, during a session about optimization, that it is unwise to do many assignments and operations in the constructor, or when declaring variables outside functions; for, the compiler does not put those sections through any vigorous optimization.

    This would leave me to believe that it is best to declare your variables outside of your functions, and then assign them in an initialization function, unless these were variables passed along to the constructor as parameters and you want to avoid passing them along again.

    package{
    
     public MyClass {
    
       private var myA1:Number; //declare here 
       public var myA2:Number;  //declare here
    
       public function MyClass(arg1:Number = 10):void{
           myA1 = arg1;//assigns myA1 a Number passed into the constructor, or 10
           init();
       }
       public init():void{
           myA2 = 20;  //assigns myA2 a value of 20
       }
     }
    }
    

    As well, after a search on google I found this article that seems to agree.

    http://voices.yahoo.com/flash-actionscript-3-optimization-guide-part-1-4793274.html

    Keep in mind, that you may just want to do things a certain way that makes things easier for you, and then optimize later; for, just getting it done is more important than style imho.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say there's the following base class: package bg.svetlin.ui.controls; public abstract class Control { protected
Let's Say I Have This Class: package{ import flash.display.Sprite; public class Main extends Sprite{
Let's say I have the following two classes: package example.model; public class Model {
In my program, there are two class, say, category and product, with each object
Is there a clean method of mocking a class with generic parameters? Say I
Let's say you have a class with a Uri property. Is there any way
Let's say I have a Base class and several Derived classes. Is there any
In VB.NET there is a keyword 'shadows'. Let's say I have a base class
Say I have three classes: class X{}; class Y{}; class Both : public X,
Let's say we have these two classes: public class Base { public static int

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.