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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:22+00:00 2026-05-28T01:40:22+00:00

I am trying to add multiple different versions of the same button to the

  • 0

I am trying to add multiple different versions of the same button to the stage and to be able to access them later on by assigning them an ID. The way I assumed this would be done is to have a class for the button where an internal static variable is defined so that the ID can be found in the next function. This does not seem to be working, as the ID is constantly showing as the last number given, so in this case 6.

I assume that I am doing this wrong? Here is my code so you can better understand:

package src  {

import flash.display.MovieClip;
import flash.events.*;
import flash.utils.Timer;
import flash.net.*
import flash.display.Loader

public class main extends MovieClip {

public var xmlData:XML = new XML
public var currentName = null

    public function main() {
        var y = 0
        for(x=0; x<=6; x++){
            var names:namez = new namez
            namez.ID = y
            y++
            names.y = x*25
            names.addEventListener(MouseEvent.CLICK, checkMe)
            spinner.addChild(names)
        }
    }

    public function checkMe(e:MouseEvent){
        trace("clicked"+namez.ID)
    }
}
}

namez.as class:

package src {

import flash.display.MovieClip

public class namez extends MovieClip{

    internal static var ID

    public function namez() {
    }

}

}

Despite doing a trace for the buttons for namez.ID and it correctly showing 0,1,2,3,4,5,6 when the button is clicked on, the only number that shows is 6.

How do I correctly go about making dynamically added buttons accessable by other functions? Should I be using an array here?

FYI the total number of buttons required is 241.

  • 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-28T01:40:23+00:00Added an answer on May 28, 2026 at 1:40 am

    Because ID is a static variable, that means there is only one ID for all instances of namez, whereas it sounds like you want an ID for each instance. Simply remove the ‘static’ attribute and define ID as follows:

    internal var ID
    

    Good catch by Pbirkoff on how you’re accessing the .ID property, but you may also want to cast the event target to the namez class to access more custom properties.

    I also note that you’re missing some semi-colons and type definitions, which may or may not be required, but are good programming practice:

    public function main():void {
        var y:int = 0
        for (x:int = 0; x<=6; x++) {
            var names:namez = new namez();
            namez.ID = y;
            y++;
            names.y = x*25;
            names.addEventListener(MouseEvent.CLICK, checkMe);
            spinner.addChild(names);
        }
    }
    
    private function checkMe(e:MouseEvent):void {
        var names:namez = e.target as namez;
        trace("clicked" + names.ID);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add multiple instances of UIImageView(s) to an NSMutableArray of NSMutableDictionar(ies). I
I'm trying to add multiple jQuery data entries to a single element. I suspected
I'm fairly new to JQuery and I'm trying to add multiple form fields for
Ok, I am trying to add one row of multiple images to a JPanel,
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Trying to add email notification to my app in the cleanest way possible. When
I'm trying to pull multiple rows from different tables in a database. If I
In CMake, I'm trying to build a project that includes libraries for multiple different
I'm trying to add and remove multiple classes on a text field by clicking
I'm trying to learn using Caliburn.Micro with WPF. How can I add multiple views

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.