Flash Q

  • Started
  • Last post
  • 4 Responses
  • PonyBoy

    okay... gotta weird one here.

    I've got two variables that I'm adding together using the '+' operator.

    both variables are defined using .AS 2.0 as follows:

    var _thumbWidth:Number = x;
    var prev_width:Number = myMC_mc._width;

    I'm using a 'for' loop that adds those two defined variables each time the loop runs.

    Why does the '+' operator concatenate and NOT ADD the defined numbers?!!

    I get the following during a trace of the new number during each loop:

    4045
    274045
    41274045
    4341274045
    394341274045
    47394341274045
    4147394341274045
    384147394341274045

    instead of adding 40 + 45... I get a concatenated string of '4045'... but the variables are defined as Numbers...

    ... and... to make it even weirder - even the NEW VARIABLE I'm defining by adding the two old variables is also set to be a Number:

    var new_width:Number =_thumbWidth + prev_width:

    (shouldn't it add the two 'numbers' instead of making them a string if it is to be defined as a Number?)...

    I've added variables together in the exact same fashion as I am now in other projects and have NEVER encountered this...

    ... i'm going to reboot and have a diet pepsi and see if that helps.

  • Mimio0

    convert to integer? My guess is that it's getting re-typed someplace/somewhere.

  • PonyBoy0

    i thought that's what assigning the variable a value of 'Number' would do, Mimio... right?

    meh... flash... :)

  • PonyBoy0

    ahh! Mimio... yay got me the answer...

    ... even though I've declared the variable as a number - it's still reading one of my variables as a string (it's being pulled from xml)...

    so I had to wrap the final variable like this:

    var new_width:Number = Number(_thumbWidth)+prev_width;

    that forces the '_thumbWidth' variable out of being a string...neat! :)

  • jpea0

    you could also use eval

    new_width = eval(thumbWidth)+ eval(prev_width);