# Variable is Number, Acts like String

**URL:** <https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699>\
**Category:** flash\
**Created:** [April 15, 2006, 4:32pm UTC](https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699 "2006-04-15T16:32:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [April 15, 2006, 4:32pm UTC](https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699/1 "2006-04-15T16:32:31Z")

</div>

So I load a variable, length, into a LoadVars instance.

```auto

trace(this.length); //outputs 3
var tempLength:Number = this.length; //tempLength should be the number representation of the loaded value
thisObj.buttonLength = tempLength+2; //I need to add 2 onto the this.length value
trace(thisObj.buttonLength); //outputs 32, which kind of makes sense, but I need it to output 5.

```

Any ideas on how to go about this?

EDIT: Forgot to add-  
thisObj.buttonLength is declared as a number, and Flash does not output a type mismatch.

---

<div class="post-metadata">

**Author:** ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)\
**Post date:** [April 15, 2006, 5:04pm UTC](https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699/2 "2006-04-15T17:04:33Z")

</div>

try use Number() and put inside brackets what you need  
like Number(tempLength)

this.length is what?

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 15, 2006, 5:10pm UTC](https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699/3 "2006-04-15T17:10:04Z")

</div>

Ive tried your code… When I declare this.length as a string, no type mismatch warning, no nothing and the result is 32. When I declare this.length as a number, it works… It seem that type mismatch error is thrown only on direct value input as var variable:Number = “string”… I suggest you should use Number(this.length) to convert it to number.

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [April 15, 2006, 5:10pm UTC](https://forum.kirupa.com/t/variable-is-number-acts-like-string/185699/4 "2006-04-15T17:10:07Z")

</div>

Worked like a bloody charm gvozden, thanks a lot (you too, mathew.er ;))

I’m loading the number of pages from a MySQL database, the manually adding a home page on the top, and user admin page on the bottom, hence the need to add 2 to the number of pages loaded.
