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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:59:11+00:00 2026-06-18T00:59:11+00:00

i am very new to concept of array…so i need a bit help understanding

  • 0

i am very new to concept of array…so i need a bit help understanding and executing it….

so I have 5 buttons…

monday – friday

now when somebody presses one of the buttons I want the program to trace the day that was pressed only.. can somebody please explain me step by step on what to do and why?

I am using flash actionscript 3..
this is pretty much the only thing I know how to do…I’ve tried some onlint tuts but they weren’t very clear

var days: Array ["mon", "tues", "wed", "thurs", "fri"];
  • 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-18T00:59:12+00:00Added an answer on June 18, 2026 at 12:59 am

    Your Array was created wrong in your post. Try this:

    var days:Array = ["mon", "tues", "wed", "thurs", "fri"];
    

    or you could also create it like this, using the push() method of the Array class:

    var days:Array = new Array();
    days.push( 'mon');
    days.push( 'tues');
    days.push( 'weds');
    days.push( 'thurs');
    days.push( 'fri');
    

    to trace the values of the array in your post:

    trace( days[0] ); // returns "mon"
    trace( days[1] ); // returns "tues"
    trace( days[2] ); // returns "wed"
    trace( days[3] ); // returns "thurs"
    trace( days[4] ); // returns "fri"
    

    The array’s contents are stored in the array’s “indexes”. An array’s index always starts with 0.

    Array’s have a length. An empty array’s length is 0. If the array has at least one item in it, the length is 1 and increases as you add more items. To loop through your array to get the values do this:

    for(var i:int = 0; i < days.length; i++)
    {
        trace( days[i] );
    }
    

    Arrays are a powerful and essential part of any programming language. You can remove items from the array, add items, remove a specific item at a specific index, remove an item by name, combine arrays, and lots more. You’d benefit from looking at this link and studying the properties and methods of the Array class. Once you get the hang of how to manipulate Array’s you’ll never now how you existed without them!

    There are many ways to associate a button with a particular array index. The answer provided by Dr.Denis McCracleJizz is one way, although if you are as new to AS3 as you say, it might seem a little overwhelming as it uses several concepts you may not yet be familiar with. Let me see if I can simplify it a bit, although this will make the code a bit more lengthy:

    mondayButton.addEventListener( MouseEvent.CLICK, onClickDayButton );
    tuesdayButton.addEventListener( MouseEvent.CLICK, onClickDayButton );
    
    function onClickDayButton( e:MouseEvent ):void
    {
        if( e.target.name == 'mondayButton')
        {
            trace( days[0] );
        }
        else if( e.target.name == 'tuesdayButton')
        {
            trace( days [1] );
        }
    
        // and so on...
    }
    

    If you’re familiar with objects you could create an object for each button that hold both the button and the button id and store those in an array:

    var days:Array = ["mon", "tues", "wed", "thurs", "fri"];
    
    var dayButtonArray:Array = new Array();
    
    var mondayButtonObject:Object = new Object();
    mondayButtonObject.button = mondayButton;
    mondayButtonObject.id = 0;
    dayButtonArray.push( mondayButtonObject );
    
    
    var tuesdayButtonObject:Object = new Object();
    tuesdayButtonObject.button = tuesdayButton;
    tuesdayButtonObject.id = 1;
    dayButtonArray.push( tuesdayButtonObject );
    
    // and like above, the rest of the days here
    
    // then loop through them and set the mouseEvent
    
    for(var i:int = 0; i < dayButtonArray.length; i++)
    {
       dayButtonArray[i].button.addEventListener( MoouseEvent.CLICK, onClickDayButton );
    }
    
    // and the function each button calls to
    
    function onClickDayButton( e:MouseEvent ):void
    {
        trace( days[ evt.target.id ] );
    }
    

    You could further simplify the object method above by skipping the days array altogether and adding the day associated with the button right into the dayButtonArray instead of an id:

    var dayButtonArray:Array = new Array();
    
    var mondayButtonObject:Object = new Object();
    mondayButtonObject.button = mondayButton;
    mondayButtonObject.day = "monday";
    dayButtonArray.push( mondayButtonObject );
    
    
    var tuesdayButtonObject:Object = new Object();
    tuesdayButtonObject.button = tuesdayButton;
    tuesdayButtonObject.day = "tuesday";
    dayButtonArray.push( tuesdayButtonObject );
    
    // and like above, the rest of the days here
    
    // then loop through them and set the mouseEvent
    
    for(var i:int = 0; i < dayButtonArray.length; i++)
    {
       dayButtonArray[i].button.addEventListener( MoouseEvent.CLICK, onClickDayButton );
    }
    
    // and the function each button calls to
    
    function onClickDayButton( e:MouseEvent ):void
    {
        trace( evt.target.day );
    }
    

    Now were getting as complicated as Dr.Denis McCracleJizz’s answer. His is definitely worth looking at as well.

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

Sidebar

Related Questions

I am very new to Bing Maps Concept Requirement: Need to Design a Bing
I am very new to concept of IOC and I understand the fact that
I'm very new to the concept caching, so excuse me if my question is
I am very new to ajax concept,I want to submit a form without refresh
I'm new to the very concept of the Google Web Toolkit (GWT) and as
Very new to python and can't understand why this isn't working. I have a
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new to XSL (and XML for that matter), but I need to step
I'm still struggling with this concept. I have two different Person objects, very simply:
Im very new to eval() fun ction concept ,so dont judge me on syntax.

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.