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

  • SEARCH
  • Home
  • 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 8643745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:07:37+00:00 2026-06-12T12:07:37+00:00

In AS3, you can initialize a member variable (or constant) by calling a member

  • 0

In AS3, you can initialize a member variable (or constant) by calling a member function. This happens before the constructor is called. In the meantime, the ‘this’ keyword is perfectly accessible in the initializing member function even though the constructor function hasn’t been issued yet.

This sounds like a time bomb. Can anyone comment on the above practice?

Edit :

...
private var member:Sprite = getSprite(); // called before constructor
...
private function getSprite():Sprite {
    var spr:Sprite = new Sprite();
    this.addChild(spr); // 'this' used before constructor
    return spr;
}
  • 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-06-12T12:07:38+00:00Added an answer on June 12, 2026 at 12:07 pm

    As I understand it, that’s fine (if not really nice and readable). What happens when new is called is:

    1. Memory is allocated for the instance (this becomes available)
    2. All members are initialized (either to their default or whatever is specified)
    3. The constructor is called
    4. new returns this

    The danger lies in that you have to make sure that nothing in getSprite() requires something that is initialized in the constructor (including the parent constructor, if it’s called). I would avoid it and just initialize everything in the constructor instead.

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

Sidebar

Related Questions

In AS3 I can write this[foo] for access to a variable foo . I
In AS3 you can pass a constant to the compiler -define+=CONFIG::DEBUG,true And use it
In AS3 you can embed a graphic into a Class variable: [Embed(source=MenuAssets.swf, symbol=topSquare)] public
anybody can help me to change that javascript function to AS3? thanks :) function
In AS3 you have a function on a string with this signature: function replace(pattern:*,
I'm using Flash Professional cs5/AS3 I'll try and describe this the best I can.
How can I make an abstract class in AS3 nicely? I've tried this: public
How can I return a value from AS3 to javascript. I am calling a
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't
I have create a custom contextMenu using AS3 and can apply that to the

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.