try using a dictionary instead of object

----- Original Message ----
From: Paul Whitelock <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, May 15, 2008 4:11:19 PM
Subject: [flexcoders] Re: How to tell if variable is an int, uint, or a Number?


Well, it turns out that doesn't work either if the int is positive. If
an int is positive all of the follow tests return true:

var testInt:int = 5;
var obj:Object = testInt;

obj is int -> true
obj is uint -> true
obj is Number -> true

Sooooo, I'm back to assuming there is no way to tell an int from a uint.


--- In [EMAIL PROTECTED] ups.com, "Paul Whitelock" <[EMAIL PROTECTED]> wrote:
>
> I found another way that seems to work (not sure why though):
> 
> var testUint:uint = 1;
> var testInt:int = -1;
> var testNumber:Number = 1.1;
> 
> var obj:Object = testUint;
> 
> trace ("uint: " + (obj is uint && obj is int));
> trace ("int: " + (obj is int && !(obj is uint)));
> trace ("Number: " + ((obj is Number) && !(obj is int) && !(obj is
uint)));
> 
> Output:
> uint: true
> int: false
> Number: false
> 
> obj = testInt;
> 
> trace ("uint: " + (obj is uint && obj is int));
> trace ("int: " + (obj is int && !(obj is uint)));
> trace ("Number: " + ((obj is Number) && !(obj is int) && !(obj is
uint)));
> 
> Output:
> 
> uint: false
> int: true
> Number: false
> 
> obj = testNumber;
> 
> trace ("uint: " + (obj is uint && obj is int));
> trace ("int: " + (obj is int && !(obj is uint)));
> trace ("Number: " + ((obj is Number) && !(obj is int) && !(obj is
uint)));
> 
> Output:
> uint: false
> int: false
> Number: true
> 
> 
> --- In [EMAIL PROTECTED] ups.com, "Paul Whitelock" <paul@> wrote:
> >
> > Thanks! That did help, but it doesn't seem to work for a uint. Here's
> > my test code:
> > 
> > var testUint:uint = 1;
> > var testInt:int = -1;
> > var testNumber:Number = 1.1;
> > var testString:String = "test";
> > var testDate:Date = new Date();
> > var testArray:Array = new Array();
> > 
> > var test:Array = [testUint, testInt, testNumber, testString, testDate,
> > testArray];
> > 
> > for (var i:uint = 0; i < test.length; i++) {
> >     var typeInfo:String = describeType( test[i]). @name.toString( );
> >     trace(typeInfo) ;
> > }
> > 
> > And here's the output:
> > 
> > int
> > int
> > Number
> > String
> > Date
> > Array
> > 
> > I'm guessing there's no way to identify a uint -- is that correct?
> > 
> > 
> > --- In [EMAIL PROTECTED] ups.com, "Alex Harui" <aharui@> wrote:
> > >
> > > There is code that might help in
> > > DataGrid.as: itemEditorItemEd itEndHandler
> > > 
> > > ____________ _________ _________ __
> > > 
> > > From: [EMAIL PROTECTED] ups.com
> [mailto:[EMAIL PROTECTED] ups.com] On
> > > Behalf Of Paul Whitelock
> > > Sent: Thursday, May 15, 2008 12:31 PM
> > > To: [EMAIL PROTECTED] ups.com
> > > Subject: [flexcoders] How to tell if variable is an int, uint, or a
> > > Number?
> > > 
> > > 
> > > 
> > > I have a situation where an untyped variable is passed in a method
> > > call and I need to determine the data type for the variable. My
first
> > > thought was to use typeof, but typeof returns "number" for an int,
> > > uint, or a Number. The operator "is" will not work on primitives.
> > > 
> > > Is there any way to determine the data type of an untyped primitive
> > > object?
> > >
> >
>

    


      

Reply via email to