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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:56:14+00:00 2026-06-09T02:56:14+00:00

This might be a simple one, and if it is I’m sure I’ll feel

  • 0

This might be a simple one, and if it is I’m sure I’ll feel stupid.

Basically, I have arrays a1, a2 and a3.

Using a for statement..

for (var i 0; i < 4; i++) {
//stuff
}

How can I push data in the for statement into one of these arrays using i? That is, each time adding the data into the next group up. a[0] -> a[1] etc. I tried getDefinitionByName but it seems that only works for library objects!

Sorry if it’s simple!

Cheers in advance.

EDIT:

The code in full where I need this to work. This is what I tried using the first answer I was given.

var fullList:Vector.<Array> = new Vector.<Array>();

for (var i1 = 0; i1 < 3; i1++)
{
    fullList.push(new Array());
}

var levelLoader:URLLoader = new URLLoader();
levelLoader.addEventListener(Event.COMPLETE, levelLoaded);
function levelLoaded(e:Event):void
{
    var indexcount = 0;
    txttileArray = e.target.data.split("a");
    txtDebug.text = txttileArray.toString();
    for (var i = 1; i < 4; i++)
    {
        temparray1 = txttileArray[indexcount].split("");
        for (var row = 0; row < temparray1.length; row ++)
        {
            var a = getDefinitionByName(temparray1[row] + "Tile") as Class;
            //trace(a);
            var b = new a  ;
            b.x = 17 + 17 * row;
            b.y = 17 + 17 * indexcount;
            addChild(b);
            fullList[indexcount].push(b);
        }
        indexcount++;
    }
}

sorry for the messy variable names.

  • 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-09T02:56:16+00:00Added an answer on June 9, 2026 at 2:56 am

    i have three arrays, a1, a2 and a3. i want to be able access these
    arrays based on the value of the variable “i”. so for example, if “i”
    is 1, i want to push a data value to a1. and so on – hazdog

    This is not possible if you have arrays a1, a2 and a3 as local (defined in the function) variables. If they are defined in the class, then here’s how you do it:

    private var a1:Array=[];
    private var a2:Array=[];
    private var a3:Array=[];
    
    private function pushValue(identifier:String, value:Object):int {
        var name:String="a" + identifier;
        var target:Array=this[name] as Array;
        if(target == null) {
            throw new Error("No such array " + name);
        } else {
            return target.push(value);
        }
    }
    
    //And then call it like this:
    pushValue("1", "This value goes in array a1");
    pushValue("1", "This is another value that goes in array a1");
    
    pushValue("2", "This value goes in array a1");
    pushValue("2", "This is another value that goes in array a2");
    
    pushValue("3", "This value goes in array a3");
    pushValue("3", "This is another value that goes in array a3");
    

    Otherwise, you can define an array of arrays (or vector of arrays), say holderArray in which you put your target arrays, and then push the value to holderArray[identifier]

    EDIT
    Instead of defining a1, a2 and a3 in the this object, define it like this:

    private var arrayHolder:Object={};
    
    private function init():void {
        for(var i:int=1; i<=3; i++) {
            arrayHolder["a" + i]=new Array();
        }
    }
    
    init();
    

    Then, your arrays will be stored as arrayHolder.a1, arrayHolder.a2, arrayHolder.a3 etc
    And modify pushValue as follows:
    Change

    var target:Array=this[name] as Array;
    

    to

    var target:Array=arrayHolder[name] as Array;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple one, but since I don't have much knowledge about
This might be a simple one for you guys, im learning Javascript and have
This one might be simple, but here it is anyway. I have a List<Object>
This might be simple but I am new to Oracle. I am using Oracle
Ok, this might sound simple but am not sure what to do. I am
This might be simple one but I am finding it very difficult to work
This might be a simple one, but I can't seem to find an easy
This might be simple one, since it's a design question mode than development (
This might be a simple one but I just can't seem to nail it
This might be a simple question.but,does any one know how to disable a button

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.