I mean,
if Array could be used as a casting operator, Array( aCollection ) would throw an error, wouldn't it?
Cheers,
Ralf.

On 8/8/06, Ralf Bokelberg <[EMAIL PROTECTED]> wrote:
Hm, I don't understand the relation to Proxy here.
ArrayCollection doesn't inherit from Array, so aCollection as  Array returns null, regardless of ArrayCollection implementing proxy or not.
Seems like i'm missing something

Cheers,
Ralf.

On 8/8/06, Ted Patrick < [EMAIL PROTECTED]> wrote:

Ralf,

 

(Sorry I think my post was a bit confusing in retrospect.)

 

ArrayCollection does not inherit from Array thus MyArray will always return null.

 

aCollection = new ArrayCollection( [1,2,3] );
myArray = aCollection as Array;

trace( myArray == null ) //true

 

With Proxy classes, inheritance stops at Proxy. The Proxy types provide a low level way to redefine and rewire a Classes interface. They are an excellent way to implement the façade or adapter patterns in AS3. How proxy types work internally is a black box (up to the developer), externally the types define an interface by overriding these methods:

 

callProperty - a method operation
deleteProperty - a delete operation
getDescendants - E4X Related operation
getProperty - a get operation
hasProperty - a has operation
isAttribute - testing the presence of an attribute in XML/E4X
nextName - enumeration support
nextNameIndex - enumeration support
nextValue - enumeration support
setProperty - a set operation

 

If you want to provide an alternate interface to any object, Proxy is an excellent place to start.

 

Here is some more background on Proxy:

 

http://www.onflex.org/ted/2006/04/magic-with-flashutilproxy.php

 

If you arrived here from FlashLand, Proxy is __resolver on steroids. J

 

Cheers,

 

Ted J

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Ralf Bokelberg
Sent: Tuesday, August 08, 2006 9:41 AM


To: [email protected]
Subject: Re: [flexcoders] any performance hit using "as"?

 

Hi Ted,
maybe i misunderstand you,
but your example works like expected for me.

myArray = aCollection as Array;

Since aCollection is not an Array, myArray is null afterwards.

Cheers,
Ralf.

On 8/8/06, Ralf Bokelberg < [EMAIL PROTECTED]> wrote:

Huh,
i'd expect that myArray is null, because aCollection is not an Array.
Cheers,

Ralf.

 

On 8/8/06, Ted Patrick < [EMAIL PROTECTED]> wrote:

Using 'as' can get confusing as it has a subtle gotcha. 'as' will return the object if it inherits from the target Class else it returns null.

 

This is great behavior until you try it with Classes that inherit from Proxy.

 

Example: myVar will be null, 100% of the time!!!

 

var aCollection:ArrayCollection;

var myArray:Array;

 

aCollection = new ArrayCollection( [1,2,3] );

myArray = aCollection as Array;

 

ArrayCollection does not inherit from Array, it holds an array internally and uses Proxy to provide an alternative interface.

 

Cheers,

 

Ted Patrick

Flex Evangelist

Adobe Systems Incorporated

 

 


From: [email protected] [mailto:[email protected]] On Behalf Of Pan Troglodytes
Sent: Tuesday, August 08, 2006 8:11 AM
To: [email protected]
Subject: Re: [flexcoders] any performance hit using "as"?

 

Thanks for the reply, Matt.  Is there any performance difference between all three?  I'm curious if doing any casting at all is a performance hit.

On 8/7/06, Matt Chotin < [EMAIL PROTECTED]> wrote:

I don't think there should be a performance difference between the two.

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of Pan Troglodytes
Sent: Monday, August 07, 2006 9:21 AM
To: flexcoders
Subject: [flexcoders] any performance hit using "as"?

 

I tend to like to make my code autosense for me, so sometimes I do things like this:

MyObjectType(grid.selectedItem).somefield = 3;

I assume that adds no overhead, since it is a straight cast (though I could be wrong), since I have seen runtime errors specifically telling me my cast was wrong.  But sometimes with Array, I have to use "as" because it gets a cast confused with a new array contructor.  So I'm wondering what the difference in performance is, if any.

Given then grid.selectedItem is MyObjectType, consider the following statements:

grid.selectedItem.somefield = 3;
MyObjectType(grid.selectedItem).somefield = 3;
(grid.selectedItem as MyObjectType).somefield = 3;


Is there any runtime performance difference to them?  I only just now read the help on "as" I noticed that if it is NOT the desired type, it returns null.  That totally messes with my brain, coming from a Delphi background where as throws an exception if it is not the right type.  But the thrust of my question involves them being the desired type.

--
Jason




--
Jason





--
Ralf Bokelberg < [EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany




--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany




--
Ralf Bokelberg <[EMAIL PROTECTED] >
Flex & Flash Consultant based in Cologne/Germany



--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to