Groups | Blog | Home
all groups > flash actionscript > june 2005 >

flash actionscript : Simple problem?


DHz2
6/5/2005 11:45:48 PM
I suspect this is a real "newbie" problem, but I have the following code snip
that doesn't work correctly:

var tempOne:Number = 123.45;
var tempTwo:Number = 0;
// tempTwo should be the same both times...
tempTwo = Math.round(123.45);
trace(tempTwo);
tempTwo = Math.round(tempOne);
trace(tempTwo);

... but the output from trace is

123
undefined

I'd appreciate it if someone could tell me what I'm doing wrong here.

Thanks.



Rothrock
6/6/2005 12:00:00 AM
Sorry can't help. I know nothing about DataSet and DataGrid components.

First thing I would do is add the following at the end:

trace(tempOne);
trace(Math.round(tempOne));

Other things I would do are to remove the strict typing. Surprisingly it can
sometimes cause problems.

I flash therefore I am
6/6/2005 12:00:00 AM
I don't know if this makes any difference but I believe the datagrid is
populated with an array and, although you can do some math, I think I
remember data typing and conversion can be issues that need to be resolved.
Just because you type a variable, it doesn't mean it stays that type. Don't
get too distracted by that - it is just a suggestion to consider.

Rothrock
6/6/2005 12:31:31 AM
DHz2
6/6/2005 12:41:52 AM
Thanks. I cut and pasted the code here into a new Flash doc and it works
correctly, as you observed. But I did the same in the original doc and it
doesn't. So there's some difference between them. Thanks for the feedback. I'll
keep working on it.

:)
DHz2
6/6/2005 1:14:09 AM
So here's some more detail, which seems to move me forward a bit.

I'm just trying Flash out for a project, and used the DataSet and DataGrid
components to read in a simple XML file. All that works fine. One element of
the DataGrid is a calculated field which is populated from data in another
column. In the 'on(load)' function, the following code works fine:

var tempOne:Number = 123.45;
var tempTwo:Number = 0;
// tempTwo should be the same both times...
tempTwo = Math.round(123.45);
trace(tempTwo);
tempTwo = Math.round(tempOne);
trace(tempTwo);

However, if I move this same code to the 'on(calc)' function, it doesn't work
and I get an "undefined" on the second trace. I can do other calculations OK in
the function -- populate my additional column and so on -- but the Math methods
don't seem to see the variable correctly. I'd guess this has to be some sort of
a scoping issue, but for the life of me, I can't see what it is.

Any help would be appreciated.

Thanks.
AddThis Social Bookmark Button