A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [CS4] Sequential Names

  1. #1
    Member
    Join Date
    Dec 2009
    Posts
    84

    [CS4] Sequential Names

    I am somewhat new to AS3 and am really starting to get the hang of it. I have run into a problem though. Say I have 20 combo boxes named combo1, combo2, ...combo20. If I wanted to trace the value of them all in one function I would do something like the following:
    PHP Code:
    for(i=1;i<=20;i++){
    trace(_root["combo"+i].value);

    This does not work in AS3 since _root has been deprecated. I know that the closest match to _root is stage, but I cannot figure out how to get this to work. I have tried reaplacing _root with stage, _stage, and this, but none of them work. I am sure there is something simple I am missing here, but I can't figure it out. Any help would be apprecaited. Thanks.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The closest match to _root is actually root. But you still don't want to do that.
    Ideally you would not have 20 individual variables named sequentially. That sort of thing is almost always better handled by putting objects in an array.

    But if you placed these 20 combo boxes on the stage by hand, you can use getChildByName. I would suggest only using that to get them in an array.
    Code:
    var combos:Array = [];
    for (var i:int = 1; i < 20; i++){
      combos.push(getChildByName("combo"+i));
    }
    Then you can handle them sanely. To get combo1, use combos[0] (since arrays are 0-based).
    Code:
    trace(combos[0].value);

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