Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-27 Thread Mark Carter

Oops, sorry. Thanks, you're right!

FlexBuilder code completion wasn't giving me the chance to put a variable
after is - so I just assumed it wasn't possible (like in Java).


andrii_olefirenko wrote:
 
 obj is cls  - it works for me, no compile error (Flex SDK 3).
 

-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-method--tp20171501p20182274.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-27 Thread Josh McDonald
Yeah, builder's not so smart when you're trying to do anything out of the
ordinary :)

On Mon, Oct 27, 2008 at 4:01 PM, Mark Carter [EMAIL PROTECTED] wrote:


 Oops, sorry. Thanks, you're right!

 FlexBuilder code completion wasn't giving me the chance to put a variable
 after is - so I just assumed it wasn't possible (like in Java).


 andrii_olefirenko wrote:
 
  obj is cls  - it works for me, no compile error (Flex SDK 3).
 

 --
 View this message in context:
 http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-method--tp20171501p20182274.html
 Sent from the FlexCoders mailing list archive at Nabble.com.


 

 --
 Flexcoders Mailing List
 FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Alternative FAQ location:
 https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
 Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
 Links






-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

Like the cut of my jib? Check out my Flex blog!

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]
:: http://flex.joshmcdonald.info/


Re: Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-27 Thread Mark Carter

Hi Mike - sorry, you've lost me there...

The few tests I've done show that obj is cls is what I need. Are you
saying that does not work?


Michael Schmalle wrote:
 
 Adding to the insight, if you wanted to use the 'is' operator with those
 two
 arguments, you need to create an instance of the Class and then use the
 'is'
 operator.
 This would let you know if it is an instance of the object passed.
 
 public static function
 isObjectInstanceOfClass(obj:Object, cls:Class):Boolean
 {
 return obj is new cls();
 }
 
 We have asked the player engineers about the performance hit on this is
 not
 as bad as describeType in some instances.
 
 
 Mike
 

-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-method--tp20171501p20190188.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-27 Thread Eric Cooper
The question has been answered (yes, it is possible to use is as part of 
isInstanceOf() method. Here's an example of my use of 
this mechanism (for determining if geometric shapes share an instance of a 
particular class of constraint, e.g. are these two line 
segments perpendicular to each other?)

public function sharesConstraintWith(that:MPShape, 
constraintClass:Class):MPConstraint
{
// Get those constraints that are shared between this 
and that, if there are any.
for each (var c0:MPConstraint in this.constraints)
{
for each (var c1:MPConstraint in 
that.constraints)
{
if (c0 == c1  c0 is constraintClass)
return c0;
}
}
return null;
}

It works for me.
-Eric


--- In flexcoders@yahoogroups.com, Mark Carter [EMAIL PROTECTED] wrote:

 
 Hi Mike - sorry, you've lost me there...
 
 The few tests I've done show that obj is cls is what I need. Are you
 saying that does not work?
 
 
 Michael Schmalle wrote:
  
  Adding to the insight, if you wanted to use the 'is' operator with those
  two
  arguments, you need to create an instance of the Class and then use the
  'is'
  operator.
  This would let you know if it is an instance of the object passed.
  
  public static function
  isObjectInstanceOfClass(obj:Object, cls:Class):Boolean
  {
  return obj is new cls();
  }
  
  We have asked the player engineers about the performance hit on this is
  not
  as bad as describeType in some instances.
  
  
  Mike
  
 
 -- 
 View this message in context: 
 http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-
method--tp20171501p20190188.html
 Sent from the FlexCoders mailing list archive at Nabble.com.






Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-27 Thread Michael Schmalle
I messed up, what I said does not work, to early in the morning for me. :)
'is' tests an instance to a class reference. I was thinking in the opposite
direction when I gave that example.

Eric shows you.

Mike

On Mon, Oct 27, 2008 at 11:41 AM, Eric Cooper [EMAIL PROTECTED] wrote:

   The question has been answered (yes, it is possible to use is as part
 of isInstanceOf() method. Here's an example of my use of
 this mechanism (for determining if geometric shapes share an instance of a
 particular class of constraint, e.g. are these two line
 segments perpendicular to each other?)

 public function sharesConstraintWith(that:MPShape,
 constraintClass:Class):MPConstraint
 {
 // Get those constraints that are shared between this and that, if there
 are any.
 for each (var c0:MPConstraint in this.constraints)
 {
 for each (var c1:MPConstraint in that.constraints)
 {
 if (c0 == c1  c0 is constraintClass)
 return c0;
 }
 }
 return null;
 }

 It works for me.
 -Eric


 --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Mark
 Carter [EMAIL PROTECTED] wrote:
 
 
  Hi Mike - sorry, you've lost me there...
 
  The few tests I've done show that obj is cls is what I need. Are you
  saying that does not work?
 
 
  Michael Schmalle wrote:
  
   Adding to the insight, if you wanted to use the 'is' operator with
 those
   two
   arguments, you need to create an instance of the Class and then use the
   'is'
   operator.
   This would let you know if it is an instance of the object passed.
  
   public static function
   isObjectInstanceOfClass(obj:Object, cls:Class):Boolean
   {
   return obj is new cls();
   }
  
   We have asked the player engineers about the performance hit on this is
   not
   as bad as describeType in some instances.
  
  
   Mike
  
 
  --
  View this message in context:
 http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-
 method--tp20171501p20190188.html
  Sent from the FlexCoders mailing list archive at Nabble.com.
 

  




-- 
Teoti Graphix, LLC
http://www.teotigraphix.com

Teoti Graphix Blog
http://www.blog.teotigraphix.com

You can find more by solving the problem then by 'asking the question'.


[flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-26 Thread Mark Carter

I've got an array of objects which I want to filter according to the object's
class. The class itself is referenced by a variable so I cannot use the is
operator.

I'd like to be able to do something like:

filterClass.isInstance(obj)

Do I need to use isPrototypeOf()? - I don't really understand what that
means.
-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-method--tp20171501p20171501.html
Sent from the FlexCoders mailing list archive at Nabble.com.



Re: [flexcoders] Equivalent to Java's Class.isInstance(Object) instance method?

2008-10-26 Thread Mark Carter

I don't think that works when I have a variable of Class type.

public static function isObjectInstanceOfClass(obj:Object,
cls:Class):Boolean {
   return obj is cls; // compile error
}


florian.salihovic wrote:
 
 You are searching for the is-operator:
 
 var displayObject:DisplayObject = new Sprite();
 trace(displayObject is DisplayObject);
 trace(displayObject is Sprite);
 trace(displayObject is UIComponent);
 
 Best regards
 
 --- In flexcoders@yahoogroups.com, Mark Carter [EMAIL PROTECTED] wrote:

 
 I've got an array of objects which I want to filter according to the
 object's
 class. The class itself is referenced by a variable so I cannot use the
 is
 operator.
 
 I'd like to be able to do something like:
 
 filterClass.isInstance(obj)
 
 Do I need to use isPrototypeOf()? - I don't really understand what that
 means.
 -- 
 View this message in context:
 http://www.nabble.com/Equivalent-to-Java%27s-
 Class.isInstance%28Object%29-instance-method--tp20171501p20171501.html
 Sent from the FlexCoders mailing list archive at Nabble.com.

 
 
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-Java%27s-Class.isInstance%28Object%29-instance-method--tp20171501p20172786.html
Sent from the FlexCoders mailing list archive at Nabble.com.