A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Array problem, can you spot a flaw?

  1. #1
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142

    SOLVED Array problem, can you spot a flaw?

    Hi,

    I have a problem with an function in my movie, I want to pick from an array but I need to choose the array dynamically. index [0] from my35Array or my1Array - I don't get it to work, can you spot an flaw or suggest something that works?

    Code:
    				
    my35Array = ["1.0"]; // vildhet 35
    my1Array = ["4.9","4","3.7","3.5","2.8","2.2","0.3","0.2","0.16","0.12"]; // vildhet 1
    trace (dragg);
    
    function vildhetsdragg(vildhet,fas4)
    	{
    		toNumber (vildhet);
    		toNumber (fas4);
    		
    		
    		arrayfighter = vildhet;
    		// trace (arrayfighter);
    		bonusfighter =  "my" + arrayfighter + "Array";
    		extrafighter = bonusfighter;
    		// toString (bonusfighter);
    		trace (extrafighter); 
    		trace (fas4);
    		
    		if (fas4 > 89)
    			{
    				// trace (extrafighter[0]);
    				trace (my35Array[0]);
    				dragg = extrafighter[0];
    				
    						
    				}
    
    		
    			}
    bonusfighter and extrafighter becomes myXArray as it should (in this case 1 or 35 is the only Arrays created), but dragg = extrafighter[0]; does not pick e.g. my35Array[0] even if extrafighter is my35Array !

    dragg = extrafighter[0] is always 109 for some reason I cannot understand!

    Can you spot a flaw or tell me how to pick from the array with an dynamic way?
    Last edited by SirN; 03-29-2010 at 05:54 PM.
    http://www.sdax.se Chess, Trotting and Blog

  2. #2
    Senior Member SirN's Avatar
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    142
    I've found an solution! Hurray!

    I need to do 99 diffferent copy proccesses between 2 Arrays of it:

    if (vildhet == 1) // 1-99 needs the same treatment
    {
    bonusfighterArray[0] = my1Array[0];
    // there will perhaps be as many as 30
    // Array indexes, but not more...
    }

    if (fas4 > 89) // there will perhaps be as many as 30 conditions here
    {
    dragg = bonusfighterArray[0];
    }

    This does the job, but I would perhaps be better of if there is a way to copy an array (all the contents of it without haveing to spell it out like I here show that I am about to do), is there a way to completely copy all of an Array to another?
    http://www.sdax.se Chess, Trotting and Blog

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    extrafighter = extrafighter.concat(this["my"+arrayfighter+"Array"]);

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