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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:38:19+00:00 2026-05-23T00:38:19+00:00

I have a class which at the moment is quite messy/repetitive: public class AvFramework

  • 0

I have a class which at the moment is quite messy/repetitive:

public class AvFramework extends Object
{
    // vars
    private var _handler:AvHandler;
    private var _keyboard:AvKeyboard;
    private var _manager:AvManager;

    /**
     * Constructor
     */
    public function AvFramework()
    {
        _handler = new AvHandler();
        _keyboard = new AvKeyboard();
        _manager = new AvManager();

        // attach
        _handler.framework = this;
        _keyboard.framework = this;
        _manager.framework = this;
    }

    /**
     * Getters
     */
    public function get keyboard():AvKeyboard{ return _keyboard; }
    public function get manager():AvManager{ return _manager; }
}

This class is only going to need to make use of more and more classes, and I don’t really want to have 3 huge lists for this like above.

Is there a way to do the above dynamically – maybe using getDefinitonByName() in a loop of strings to represent the classes I want to create.

I also want the properties to be read-only and to be accessed via framework.myDynamicVarHere.

I’m thinking something along these lines:

  1. I create a list of the classes I want to create instances of, paired with the variable name they should be accessed by.
  2. I will need to make the class dynamic so that I can set the vars via this["var"] = new Blah();

Quick snippet of where my thoughts are going:

var required:Object =
{
    keyboard: "avian.framework.background.AvKeyboard",
    manager: "avian.framework.background.AvManager",
    handler: "avian.framework.background.AvHandler"
};

var i:String;
for(i in required)
{
    var Req:Class = Class(getDefinitionByName(required[i]));

    this[i] = new Req();
    AvFrameworkObject(this[i]).framework = this;
}

Just not sure how I would be able to make these read-only.

  • 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-23T00:38:20+00:00Added an answer on May 23, 2026 at 12:38 am

    You can use Proxy class to control get/set call and complete Eugeny89 answer.
    Look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Proxy.html or http://blog.joa-ebert.com/2007/05/25/as3-proxy-example/

    var required:Object =
    {
        keyboard: "avian.framework.background.AvKeyboard",
        manager: "avian.framework.background.AvManager",
        handler: "avian.framework.background.AvHandler"
    };
    ...
    
    import flash.utils.Proxy;
    import flash.utils.flash_proxy;
    public dynamic class AvFramework extends Proxy { 
        private var holder: Object = {};
    
        public function AvFramework() {
            var i:String;
            for(i in required)
            {
                var Req:Class = Class(getDefinitionByName(required[i]));
                var name = //get Class name from required[i] e.g. AvKeyboard from avian.framework.background.AvKeyboard
                holder[name] = new Req();
                holder[name].framework = this;
            }
        }
    
        flash_proxy override function getProperty( name: * ): *
        {
            return holder[name];
        }
    
        flash_proxy function setProperty(name:*, value:*):void
        {
            // Do nothing
        }
    }
    

    With this code, when you do myAvFrameworkObj.something, getProperty() is automaticaly call and you get property name from “name” variable.

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

Sidebar

Related Questions

I have class which have one public method Start , one private method and
At the moment inside the class I have ArrayList which the objects are stored
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I have class A which extends the Activity class. This class is in package
I have class World which manages creation of object... After creation it calls afterCreation
I have a class which I can write like this: class FileNameLoader { public:
I have a class which extends UIComponent and draws directly onto a Sprite contained
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class Employee which is something like this. class Emp { int EmpID;
I have a class which is in charge for error handling. I would like

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.