263 posts
  • 8 Years of Membership
  • Antarctica
  • Author Level 2
  • Collector Level 1
+2 more
x360c
says

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

3868 posts
  • 9 Years of Membership
  • Affiliate Level 5
  • Author Level 5
  • Beta Tester
+10 more
flashjunkie
says

var variablename:String = “blah”;

trace(typeof(variablename));

263 posts
  • 8 Years of Membership
  • Antarctica
  • Author Level 2
  • Collector Level 1
+2 more
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
  • 8 Years of Membership
  • Antarctica
  • Author Level 2
  • Collector Level 1
+2 more
x360c
says

Any solutions?

755 posts
  • 9 Years of Membership
  • Affiliate Level 3
  • Author Level 6
  • Beta Tester
+6 more
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



282 posts
  • 8 Years of Membership
  • Affiliate Level 5
  • Author Level 7
  • Bundle Boss
+6 more
JoeMC
says

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

263 posts
  • 8 Years of Membership
  • Antarctica
  • Author Level 2
  • Collector Level 1
+2 more
x360c
says

Go Joe! Thanks man.

by
by
by
by
by
by