The best I could do is posted below. I could not make a distinction between
uint and int if the int is positive. To me it is unclear if the value
is represented as signed or unsigned integer within the player itself. It
is clear however that a positive (int) value is automatically serialized to
a uint if writen as an object.
What I would like to know however is why you would need this. I am very
curious what that knowledge could be usefull for.
*package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.utils.getQualifiedClassName;
public class testAS extends Sprite
{
static public const UNDEFINED:int = 0x00;
static public const NULL:int = 0x01;
static public const FALSE:int = 0x02;
static public const TRUE:int = 0x03;
static public const INT:int = 0x04;
static public const NUMBER:int = 0x05;
static public const STRING:int = 0x06;
static public const XML_DOC:int = 0x07;
static public const DATE:int = 0x08;
static public const ARRAY:int = 0x09;
static public const OBJECT:int = 0x0A;
static public const XML:int = 0x0B;
static public const BYTE_ARRAY:int = 0x0C;
public function testAS()
{
var a:uint = 1;
var b:int = -1;
var c:Number = -1.5;
var d:Object = new Object();
var e:Array = new Array();
var f:Sprite = new Sprite();
trace(_getType(a));
trace(_getType(b));
trace(_getType(c));
trace(_getType(d));
trace(_getType(e));
trace(_getType(f));
};
private function _getType(value:Object):String
{
var type:String;
var ba:ByteArray = new ByteArray();
ba.writeObject(value);
ba.position = 0;
switch (ba.readByte())
{
case UNDEFINED:
type = "undefined";
break;
case NULL:
type = "null";
break;
case FALSE:
type = "Boolean";
break;
case INT:
type = (ba.readByte() >> 31) && 1 ? "int" : "uint";
break;
case NUMBER:
type = "Number";
break;
case STRING:
type = "String";
break;
case XML_DOC:
type = "XMLDocument";
break;
case DATE:
type = "Date";
break;
case ARRAY:
type = "Array";
break;
case OBJECT:
type = getQualifiedClassName(value);
break;
case XML:
type = "XML";
break;
case BYTE_ARRAY:
type = "ByteArray";
break;
default:
type = "unknown";
break;
};
return type + " - " + getQualifiedClassName(value);
};*
Greetz Erik
On 5/15/08, Paul Whitelock <[EMAIL PROTECTED]> wrote:
>
> 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] <flexcoders%40yahoogroups.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] <flexcoders%40yahoogroups.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])[EMAIL PROTECTED]();
> > > 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] <flexcoders%40yahoogroups.com>,
> "Alex Harui" <aharui@> wrote:
> > > >
> > > > There is code that might help in
> > > > DataGrid.as:itemEditorItemEditEndHandler
> > > >
> > > > ________________________________
> > > >
> > > > From: [email protected] <flexcoders%40yahoogroups.com>
> > [mailto:[email protected] <flexcoders%40yahoogroups.com>] On
> > > > Behalf Of Paul Whitelock
> > > > Sent: Thursday, May 15, 2008 12:31 PM
> > > > To: [email protected] <flexcoders%40yahoogroups.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?
> > > >
> > >
> >
>
>
>