A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Error while finding object's index in an array

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    83

    Error while finding object's index in an array

    I've an array with some properties. When I try to find an object's index I'm getting error TypeError: Error #1009. I'm using Flash CS6.

    Here's my array:

    Code:
    var squareArr:Object  = {
         a1: {
              piece: wr1_txt,
              pieceLoc: {  
                x: "-3",
                y: "347"
              }
         },
         b1: {
              piece: wn1_txt,
              pieceLoc: {  
                x: "47",
                y: "347"
              }
         },
    ...
    Below code is giving me error #1009 while I want it to return a1:

    Code:
    trace (squareArr.indexOf(wr1_txt));
    I tried:

    Code:
    var s:String;
    var found:Boolean=false;
    for (s in squareArr) {
        if (squareArr[s].piece == wr1_txt) { // YAY found it
            found=true;
            break;
        }
    }
    if (found) trace(s); else trace("Not found!");
    but it says not found
    Last edited by onurcan1977; 05-28-2014 at 09:21 AM.

  2. #2
    FK Romeo martiansam's Avatar
    Join Date
    Oct 2001
    Location
    Bombay, India
    Posts
    223
    Code:
    var tempObj:Object = new Object();
    
    var a1:Object = new Object();
    a1.piece = "wr1_txt";
    tempObj.xLoc = -3;
    tempObj.yLoc = 347;
    a1.pieceLoc = tempObj;
    
    var b1:Object = new Object();
    b1.piece = "wn1_txt";
    tempObj = new Object();
    tempObj.xLoc = 47;
    tempObj.yLoc = 347;
    b1.pieceLoc = tempObj;
    
    var squareArr:Array  = new Array();
    squareArr = [a1, b1];
    
    var len:int = squareArr.length;
    
    for(var i=0; i<len; i++)
    {
    	var obj:Object = squareArr[i] as Object;
    	
    	if(obj.piece == "wn1_txt")
    	{
    		trace(i);
    		break;
    	}
    }
    sameer rao

    there...you see!!

  3. #3
    Member
    Join Date
    Nov 2007
    Posts
    83
    thanks for the reply. but it doesn't trace a1 or b1.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    PHP Code:
    var squareArr:Object = {
        
    a1:{piece"wr1_txt",pieceLoc:{x: -3y347}}
        ,
        
    b1:{piece"wn1_txt",pieceLoc:{x47y347}} 
    };

    var 
    s:String;
    var 
    found:Boolean false;
    for (
    s in squareArr) {
        if (
    squareArr[s].piece == "wn1_txt") {
            
    found true;
            break;
        }
    }
    if (
    foundtrace(s); else trace("Not found!"); 

Tags for this Thread

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