A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Dynamic Arrays

  1. #1
    Member
    Join Date
    Mar 2006
    Posts
    43

    Dynamic Arrays

    I am looking through a for loop and I need to add a string to an array each time... I tried just _global.buttonArray = "test" + i; but each object ends up undefined at the end... here is an overview of my code

    Code:
    for (var i = 0; i < 5; i++)
    {
         _global.buttonArray[i] = "test" + i;
         trace(_global.buttonArray[i]);
    }

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Try changing global to _root after defining the array on the root level (has more or less the same effect as global)
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    You must first tell flash that you want it to be an array, then you should have no problems.
    Code:
    _global.testArray = new Array();
    
    for( var i = 0; i < 5; i++ ) {
    	_global.testArray[i] = "test" + i;
    }
    
    trace( _global.testArray );
    If you can read this, you're in the right place.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    _global.testArray = new Array();

    for( var i = 0; i < 5; i++ ) {
    testArray[i] = "test" + i;
    }

    trace(testArray );

    After saying that something is global, you don't need to keep stating that you're targeting the global one, It's global for a reason.
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center