263 posts
  • Antarctica
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 100 and 1 000 dollars
x360c says

How could I go about telling if a variable is an array or a string?

3868 posts
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 7-8 years
+4 more
flashjunkie says

var variablename:String = “blah”;

trace(typeof(variablename));

263 posts
  • Antarctica
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 100 and 1 000 dollars
x360c says

Yeah, but that returns as an object when it’s an array. Null is also classified as an object so it’s conflicting. Any other methods?

263 posts
  • Antarctica
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 100 and 1 000 dollars
x360c says

Any solutions?

755 posts
  • Beta Tester
  • Bought between 100 and 499 items
  • Croatia
  • Exclusive Author
  • Has been a member for 7-8 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
djankey says
var myString:String="djankey";
var myArray:Array=["djankey", "as-flash.com"];

Object.prototype.getTypeOf = function(obj){
    if (arguments.length) var my = obj;
    else var my = this;
    var t = ["Array","Boolean","Button","Color","Date","Function","LoadVars","MovieClip","Number","Object","Sound","String","TextField","TextFormat","XML","XMLSocket"];
    var i, l = t.length;
    for(i=0; i<l; i++) if (my.constructor == new [t[i]]().constructor) return t[i];
    return null;
}

trace(getTypeOf(myString));
trace(getTypeOf(myArray));

senocular: getTypeOf() – typeof alternative, recognizes more object types



263 posts
  • Author had a File in an Envato Bundle
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 100 and 199 users
  • Sold between 50 000 and 100 000 dollars
  • United States
JoeMC says

if (myVariable is Array){ trace(“true”); }

263 posts
  • Antarctica
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 100 and 1 000 dollars
x360c says

Go Joe! Thanks man.

by
by
by
by
by
by