Well, the == operator produces a lot of "interesting" behavior. That's why 
there's a === operator. ☺

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Dave Glasser
Sent: Thursday, August 13, 2009 4:39 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***


By my reading, everything seems to be working how it's supposed to work. But 
how it's "supposed to work" is very surprising to me. And it's not really E4X 
that's producing the odd behavior, it's the == operator. I'll go ahead and post 
the answer and explanation in my next message.

--- On Thu, 8/13/09, Gordon Smith <gosm...@adobe.com> wrote:

From: Gordon Smith <gosm...@adobe.com>
Subject: RE: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***
To: "flexcoders@yahoogroups.com" <flexcoders@yahoogroups.com>
Date: Thursday, August 13, 2009, 6:54 PM

Does anybody want to try to figure out what the E4X spec says it should do? 
It's certainly possible that the Player implementation of E4X is doing it wrong.

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Tracy Spratt
Sent: Thursday, August 13, 2009 3:10 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***


Ok, if you say so.  What is the result of your investigation?

It gets kind of complicated because AS does implicit toString() sometimes which 
can hide what is really happening.
Do:
trace(xmlList == null);
and
trace(xmlList == “null”);
return the same result?

Tracy Spratt,
Lariat Services, development services available
________________________________
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Dave Glasser
Sent: Thursday, August 13, 2009 5:22 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***


Actually, no. It would interpret it as null if it were enclosed in curly braces 
like this:

var xml:XML = <outer><inner>{null}</inner></outer>;

And even then, null might be converted to its String value, "null", as the 
content of the element. I'd have to try it to know for sure.

In the example I gave, the content of the element is a String consisting of the 
letters "n", "u", "l" and "l", in that order.

In any case, the xmlList variable would reference a non-null XMLList object. 
That's easily proven by dereferencing it:

trace("The length is " + xmlList.length());

That would output "The length is 1".

--- On Thu, 8/13/09, Tracy Spratt <tr...@nts3rd.com> wrote:

From: Tracy Spratt <tr...@nts3rd.com>
Subject: RE: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***
To: flexcoders@yahoogroups.com
Date: Thursday, August 13, 2009, 3:49 PM

Ah, I see something I missed at first.  This example is using “literal” xml, so 
the null IS getting interpreted by AS as null and not as a string.  I bet it 
would be different if you did:
var xml:XML = XML(“<outer><inner> null</inner> </outer>”);

Even so I am still surprised because the null should be the text node and the 
expression should return an XMLList with zero length.  Very interesting.

Tracy Spratt,
Lariat Services, development services available
________________________________
From: flexcod...@yahoogro ups.com [mailto:flexcoders@ yahoogroups. com] On 
Behalf Of jaywood58
Sent: Thursday, August 13, 2009 12:48 PM
To: flexcod...@yahoogro ups.com
Subject: [flexcoders] Re: *** So you think you know ActionScript? (Read 
original post first) ***



--- In flexcod...@yahoogro ups.com, "Tracy Spratt" < tracy @...> wrote:
>
> _____
>
> From: flexcod...@yahoogro ups.com [mailto:flexcod...@yahoogro ups.com] On
> Behalf Of Paul Andrews
> Sent: Wednesday, August 12, 2009 9:33 PM
> To: flexcod...@yahoogro ups.com
> Subject: Re: [flexcoders] *** So you think you know ActionScript? (Read
> original post first) ***
>
>
>
>
>
> Dave Glasser wrote:
> > Consider this code snippet:
> >
> > var xml:XML = <outer><inner> null</inner> </outer>;
> > var xmlList:XMLList = xml.inner;
> > trace(xmlList == null);
> >
> > What does the trace statement output, true or false, and why?
> >
> > Please provide an answer without running the code (of course) and, better
> yet, without consulting any documentation, or any of the other answers that
> may have been posted already (if you read the list in chronological order.)
> Pretend it's a job interview question and you have to give it your best shot
> off the top of your head.
> >
> > And also, if you don't mind, don't top-post your answer, so that if
> someone does read your answer before the original post, they might get a
> chance to answer without having seen yours first.
> >
>
> xmlList is set to point at somthing which isn't a list, so I think the
> trace statement will not be reached. That's my 02:31AM thought..
>
>
>
> All e4x expressions return an XMLList. It can be empty but is never a null.
> Besides, the characters. "null" in a text node are just a string. "null" in
> an AS comparison is a special value. The trace will display false.
> Trace("xmllist. text() =="null" ); //would return true.
>
>
>
> Tracy Spratt,
>
> Lariat Services, development services available
>

Like Tracy , I thought it would return false, for the same reason -- that 
<inner>null< /inner> would be interpreted as a string. Was surprised when I ran 
the code and saw true. What's going on? It seems like the AS decoder recognizes 
"null" as a special case.



Reply via email to