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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:33:32+00:00 2026-06-03T17:33:32+00:00

At the moment I have a class that requires information from another class, but

  • 0

At the moment I have a class that requires information from another class, but which class has to be determined at runtime based on other variables.

Effectively, I need my class BUTTON.as to be able to access GUN(1-9).as, without already knowing what number it will be.

The code that I assumed would work is this:

public function enableButton(shortcut:int):void{
        trace(ID)
        dtf_ammo.text = gun[ID].ammo
        refreshThis(shortcut, true)
        this.alpha = 1
        isActive = true
    }

ID is the number of the class (in this case, gun1).

The following does work:

public function enableButton(shortcut:int):void{
        trace(ID)
        dtf_ammo.text = gun1.ammo
        refreshThis(shortcut, true)
        this.alpha = 1
        isActive = true
    }

However, as there are 9 guns and only 1 class for the button I need to be able to use this ID variable to access functions within.

Is this possible, and if not is there a way to do what I’m trying to do here?

  • 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-03T17:33:34+00:00Added an answer on June 3, 2026 at 5:33 pm

    In order to access static properties of a class whose name is only known at runtime, you can use the following code.

    getDefinitionByName("gun" + i).ammo
    

    getDefinitionByName returns the Class object representing the class named by the String passed in. That Class object contains references to all of the static properties of the class.

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

Sidebar

Related Questions

At the moment inside the class I have ArrayList which the objects are stored
At the moment I have a combobox that is populated from the name fields
I have an object ConnectableProperty that hooks up one property to another, and requires
I have a C++ class that I'm using from my Objective-C++ controller in my
I have a class derived from HttpApplication that adds some extra features. I'm to
At the moment I have a jQuery do a POST to a Controller which
At the moment I have a DocumentViewer in a WPF window that displays an
At the moment I have the following code which works fine. label = new
Lets say I have a class that is supposed to generate some ID (for
I have a class called set that is a dynamically allocated array in 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.