A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Dynamically set a global variable?

  1. #1
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51

    Dynamically set a global variable?

    I'm trying to dynamically change values for a set of global variables and I'm beginning to wonder if it's even possible.

    The global variables are:

    _global.item1_
    _global.item2_
    _global.item3_
    (up to)
    _global.item7_


    This is the best idea I can come up with that doesn't work.

    Code:
    
    for (n = 1; n <= 7; n++) {
    	if (eval("item" + n + "_") == "new") {
    		set(_global["item" + n + "_"], "clear");
    		trace("item1_ = " + item1_);
    	}
    }
    Any help is greatly appreciated!

  2. #2
    Spit
    Join Date
    Oct 2008
    Location
    Philly, PA
    Posts
    51
    Went hunting and figured it out!!!

    Code:
    	
    for (n = 1; n <= 7; n++) {
    	if (eval("item" + n + "_") == "new") {
    		set("_global.item" + n + "_", "clear");
    		trace("item1_ = " + item1_);
    	}
    }
    I didn't realize I could put the "_global." inside of a string and it would work... silly me!

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