Skip to main content
Participant
November 22, 2014
Question

Strange behaviour in object var member assignment in single statement

  • November 22, 2014
  • 1 reply
  • 344 views

Hi,

I found this strange behaviour.

In Flash Professional For instance we have:

var dt:Date;

(dt=new Date(2014,0,1,12,00,00,0)).time+=(10*60000);
trace(dt) 

We will note that dt was not changed. I expect that dt is increased of 10 minutes, but it not so.

I repeat a similar code under CSharp and it works like expected.

Works fine otherwise the code:

var dt:Date;
dt=new Date(2014,0,1,12,00,00,0);
dt.time+=(10*60000)

trace(dt)       We will see the time increased of 10 minutes

Regards,

Giorgio

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 22, 2014

I don't know that I would call that strange behaviour moreso that I would call the way you wrote the code strange.  It might be a case where you escaped an error, but I do not see where you changed any property of dt the way you wrote it, so it is tracing the value of dt.  The second version you show is a valid way to write it and it is readily apparent that you are adjusting the time property of dt.

I think you are just processing a new date value when you write it the way you did instead of assigning the value to dt.

Run the following and see what happens...

var dt:Date;
var dd:Date

dd = new Date((dt=new Date(2014,0,1,12,00,00,0)).time+=(10*60000))
trace((dt=new Date(2014,0,1,12,00,00,0)).time+=(10*60000));
trace(dt)
trace(dd)

OOPAuthor
Participant
November 22, 2014

Hi Ned, thank you for reply.

This is a question on which one air application had wrong behavior.

your statement  dd = new Date((dt=new Date(2014,0,1,12,00,00,0)).time+=(10*60000))  resolves but appears onerous.

Let's see the other statements and their behaviours, maybe there is a problem into flash compiler?


var dt:Date;

//Notice, Ticks of 2014-01-1T12:00:00      are     1388574000000
((dt=new Date(2014,0,1,12,00,00,0)).time=(1388574000000+(10*60000)));
trace(dt);//Expected value 2014-01-01T12:10:00 and it is correct

((dt=new Date(2014,0,1,12,00,00,0)).time=dt.time+(10*60000));
trace(dt);//Expected value 2014-01-01T12:10:00 and it is correct


((dt=new Date(2014,0,1,12,00,00,0)).time+=(10*60000));
trace(dt);//Unexpected value

//This statement demostrates that setMinutes works on dt and not on another Date instance.
(dt=new Date(2014,0,1,12,00,00,0)).setMinutes(30,30,30);
trace(dt);//I expect 2014-01-01T12:30:30 and it appears correct.


//Same curious behaviour here.
//I think it is based on the same mechanism of Date:
var o:Object;

(o={uiInner:100}).uiInner+=100;
trace(o.uiInner);//Unexpected value, I expect 200

(o={uiInner:100}).uiInner=o.uiInner+100;
trace(o.uiInner);//Expected value, I expect 200 but I see 100

/*
the mechanism of resolution of:
(o={uiInner:100}).uiInner+=100;

the resolution of first parenthesis couple (o={uiInner:100}) results the new Object 'o'
on which member 'uiInner' we apply addition but is not so (see trace)

With a work around we add 100 to the uiInner member and the trace will show 200:
(o={uiInner:100}).uiInner=o.uiInner+100;
trace(o.uiInner)//Expected value, 200

It appears that (o={uiInner:100}).uiInner is initialized to ZERO when parenteses are resolved.

I checked in others compilers and I have not the earlier unexpected behaviours.
Other compilers are C#, VC++ and I am sure also Java Builder.


*/

Regards and thanks

Giorgio

kglad
Community Expert
Community Expert
November 22, 2014

i'm not sure what the point is, but some actionscript classes are chainable and some are not.  you discovered the date class is not and that the compiler throws no error when you try and chain an unchainable class.