A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] this["zoneTotal"+j] = undefined???

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    400

    [F8] this["zoneTotal"+j] = undefined???

    I think I'm declaring this wrong because I constantly get an undefined error. Can someone please help?

    Thanks!

    Code:
    var currentZone:Number = 1;
    
    for (i=0; i<4; i++) {
    	currentZone += i;
    	trace("Current Zone = "+currentZone);
    	for (j=0; j<=10; j++) {
    		this["zoneTotal"+j] += currentZone; 
    		trace("Zone Total "+j+" = "+this["zoneTotal"+j]);<-----------RETURNS UNDEFINED
    	}
    }

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    take out the "this"

    Code:
    for (j=0; j<=10; j++) {
    		this["zoneTotal"+j] += currentZone; 
    		trace("Zone Total "+j+" = "+["zoneTotal"+j]);
    }

  3. #3
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    Thanks mneil. I'm trying to return the value of the variable, not the name. Sorry for the confusion.

    So in the first iteration ...

    var zoneTotal0 += currentZone;
    trace should return "Zone Total 0 = 1"

    zoneTotal1 would equal 2, zoneTotal2 would equal 4 etc ...

    Thanks again

  4. #4
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229
    You need to set the zoneTotal variables.

    you need
    Code:
    zoneTotal0 = 1;
    zoneTotal1 = 1;
    zoneTotal2 = 1;
    etc
    Last edited by slingsrat; 05-04-2007 at 09:25 AM.

  5. #5
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    That's what I was afraid of. Is there a way to set them with a loop? I have more than 700 of them.

  6. #6
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    Found the set(). Seems to work. Thanks for the inspiration.

    Code:
    var currentZone:Number = 1;
    
    for (i=0; i<4; i++) {
    	currentZone += i;
    	trace("Current Zone = "+currentZone);
    	for (j=0; j<=10; j++) {
    		set ("zoneTotal"+j , currentZone); 
    		trace("Zone Total "+j+" = "+ this["zoneTotal"+j]);
    	}
    }

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