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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:15:32+00:00 2026-05-16T16:15:32+00:00

I am trying to make a calculator where a user can select from a

  • 0

I am trying to make a calculator where a user can select from a list of items. If a user clicks say “ITEM1”, it should add the item to a “CONTAINER_MC”. The problem i have is all my data is set inside an array containing names and prices like the code below.


var menuNames:Array = [
 "Item1",
 "Item2",
 "Item3",
 "Item4",
 "item5",
 "item6"
];

//price array
var menuPrices:Array = [
 "0.99",
 "1.99",
 "2.99",
 "5.99",
 "6.99",
 "10.99"
];

Now i have a sprite which creates a menu for each of these items by the use of a movie clip containing 2 input fields which i setup like the code below.

var menuSprite:Sprite = new Sprite(); 

var totalItems:Number = menuNames.length;
var item:menuItem; //new item field
var btn:add_btn;
for(var i = 0; i < totalItems; i++) {
 item = new menuItem(); 
 btn = new add_btn();
 menuSprite.addChild(item);
 item.addChild(btn);
 item.x = 0;
 item.y = i * 80;
 btn.y = 45;
 item.itemName.text = menuNames[i];
 item.itemPrice.text = "$" + menuPrices[i];  
}
addChild(menuSprite);

This all works fine so far, the problem is that i have a button inside my item and i need to add even listeners for these buttons, the problem is how to target these buttons. Since these buttons are added through the for loop they are not given instance names so notice how i targetted the input fields stored within the “item”, i used itemName but how would i do it to the buttons stored inside item.

Thank you, really appreciate any help possible.

  • 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-16T16:15:32+00:00Added an answer on May 16, 2026 at 4:15 pm

    Something like this:

    var menuSprite:Sprite = new Sprite(); 
    
            var totalItems:Number = menuNames.length;
            var item:menuItem; //new item field
            var btn:add_btn;
            for(var i = 0; i < totalItems; i++) {
                item = new menuItem(); 
                btn = new add_btn();
                btn.addEventListener(MouseEvent.CLICK,clickHndlr);
                menuSprite.addChild(item);
                item.addChild(btn);
                item.x = 0;
                item.y = i * 80;
                btn.y = 45;
                item.itemName.text = menuNames[i];
                item.itemPrice.text = "$" + menuPrices[i];  
            }
            addChild(menuSprite);
    
            public function clickHndlr(event:MouseEvent):void
            {
                ((event.currentTarget as add_btn).parent as menuItem).itemName.text="Any of changes";
            }
    

    But also I’d like to change arrays to Dictionary instance, like this:

    var menuData=new Dictionary();
    
            //filling our Dictionary instead of weird arrays
            for(var i:int=0;i<10;i++)
                menuData["Item"+i]=Math.round(Math.random()*100);
    
            var menuSprite:Sprite = new Sprite(); 
    
            var item:menuItem; //new item field
            var btn:add_btn;
    
            for(var menuName:Object in menuData)
            {   
                item = new menuItem(); 
                btn = new add_btn();
                btn.addEventListener(MouseEvent.CLICK,clickHndlr);
                menuSprite.addChild(item);
                item.addChild(btn);
                item.x = 0;
                item.y = i * 80;
                btn.y = 45;
    
                var menuPrice:int=menuData[menuName] as Number;
    
                item.itemName.text = menuName as String;
                item.itemPrice.text = "$" + menuPrice.toString();  
            }
            addChild(menuSprite);
    
            public function clickHndlr(event:MouseEvent):void
            {
                ((event.currentTarget as add_btn).parent as menuItem).itemName.text="Any of changes";
            }
    

    And if to be very honest, I’ll put away Flash, and prefer yo use Flex+Catalyst to create great code with great UI.

    Ask more if you need more information.

    Regards
    Eugene

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

Sidebar

Related Questions

Trying to make a make generic select control that I can dynamically add elements
I'm trying to make a calculator that will take inputs from users and estimate
I'm trying to make a select that calculates affiliate payouts. my approach is pretty
HI all. I am trying to make little program that reads data from file
I'm trying to make a simple GUI calculator in Python with Tkinter. However the
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make a generic PL/SQL procedure to export data in specific XML format,
Trying to make a web service call to an HTTPS endpoint in my Silverlight
I'm trying to make the case for click-once and smart client development but my
I'm trying to make a data bound column invisible after data binding, because it

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.