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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:21+00:00 2026-05-24T16:41:21+00:00

I’m working on a game where users can win buttons/badges as awards. I estimate

  • 0

I’m working on a game where users can win buttons/badges as awards. I estimate there will be around 500 awards, in all.

I want to allow the users to sell their duplicate/unwanted badges to the bank and buy new ones from the bank.

I am showing the badges in multiple awards frames. Below the badges, I show the count, along with a “Buy” and “Sell” button.

My question is: What’s the best way to handle SO MANY buy & sell buttons? Is there a way around coding 1000 eventListeners and 1000 eventHandlers?

One possible solution is to name my buttons, incrementally, like “buy_mc1”, “buy_mc2”, etc. Then do a loop to create listeners for this[“buy_mc” + i]. However, I would then have to make VERY sure that I link these back correctly to the awards.

Currently, I have an “award_mc” field in my database, which stores the name of the movieclip in my .fla. From that, I can access related assets, like the count field, like: this[db.award_mc + “_count”].txt.

Unfortunately, this method does not lend itself well to looped access.

Maybe I can create an array of movieclip names that are in synch with the buy/sell buttons. For example:

myArray = {aMissionAward, anotherAward, ubernessAward};

My buttons would be:
buy_0, buy_1, buy_2, etc.

When someone clicks a button, I can link buy_2 to “ubernessAward”, then look for “ubernessAward” on the database.

How can I get the number from the button, though? Even if I can loop through setting up the eventListeners, will I have to set up individuatl eventHandlers to process the correct index number?

I’m open to suggestions on another way to do this.

————————– EDIT —————————-

Here’s my solution. Props to Jens Struwe for pointing me in the right direction.

I was not able to get this to work with buttons on the stage. Apparently, buttons are a static class. MovieClips are dynamic, so I was able to get this to work by using MovieClips. Here’s what I did:

Added 3 MovieClips to the stage.
Named them “mc0”, “mc1”, and “mc2”.

Add this AS3 code:

for (var i:Number=0; i<3; i++)
{
    this["mc" + i].addEventListener( MouseEvent.CLICK, onMcClick );
    this["mc" + i].awardKey = i;
}

function onMcClick( evt:MouseEvent ):void
{
    trace("MC ID = " +(evt.target).awardKey);

    switch ((evt.target).awardKey)
    {
        case 0:
            trace("     Do stuff for 0");
            break;
        case 1:
            trace("     Do stuff for 1");
            break;
        case 2:
            trace("     Do stuff for 2");
            break;      
    }
}

From here, I can tie the awardKey to an array of MovieClip names. Then, I can use the MovieClip names to read my database.

This is why I come to Stack Overflow, FIRST, when I have a problem. 🙂

  • 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-24T16:41:22+00:00Added an answer on May 24, 2026 at 4:41 pm

    You need only one listener that can handle all of your buttons:

    1. Let your buy and sell button click events bubble.

    2. Give each button a unique identifier such as myButton.awardKey = "uberness";

    3. Register a single event listener to the container of all of your buttons.

    4. Determine the actual button clicked using event.target and the type of award using MyButton(event.target).awardKey.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I am using Paperclip to handle profile photo uploads in my app. They upload

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.