# Declaring Variables

**URL:** <https://forum.kirupa.com/t/declaring-variables/17188>\
**Category:** flash\
**Created:** [April 2, 2003, 11:33am UTC](https://forum.kirupa.com/t/declaring-variables/17188 "2003-04-02T11:33:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stimulateme](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@stimulateme](https://forum.kirupa.com/u/stimulateme)\
**Post date:** [April 2, 2003, 11:33am UTC](https://forum.kirupa.com/t/declaring-variables/17188/1 "2003-04-02T11:33:00Z")

</div>

I was just wondering cause I dont really know my flash…  
In Visual Basic you can declare a variable for example:

Dim myvariable As Integer

This only allows the variable - myvariable - to hold numbers and wont allow any other data type.

Since Flash doesnt require this its sometimes easier. But declaring also has it advantages because whenever you modify that variable it will act as whatever you stated at the begining. I know in flash you can just change the data type whenever you wish to modify it but i was wondering if there is a way to declare it at the begining so that it will always act as that data type.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 2, 2003, 3:41pm UTC](https://forum.kirupa.com/t/declaring-variables/17188/2 "2003-04-02T15:41:19Z")

</div>

A way to act solely as that data type… Well they have several types you can set it to… But they are defined as Objects…

Just define it like this…

anyarray = new Array()  
num = new Number();  
bool = new Boolean();  
date = new Date();  
str = new String();

Check them out ;)… They have numerous methods stated for them… 🙂

playamarz :player:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 2, 2003, 4:44pm UTC](https://forum.kirupa.com/t/declaring-variables/17188/3 "2003-04-02T16:44:58Z")

</div>

Flash is not strongly typed at all, so you can do pretty much anything with anything. I don’t have Flash here so I can’t test it, but I wonder what that code would return:

```auto
my_str = new String ("12");
my_str *= 2;
trace (my_str);

```

pom 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 2, 2003, 6:28pm UTC](https://forum.kirupa.com/t/declaring-variables/17188/4 "2003-04-02T18:28:16Z")

</div>

Aha! It returns 24, so it won’t behave like a string anyway. The only advantage of declaring variables with the constructor is that class methods execute faster 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 3, 2003, 7:12am UTC](https://forum.kirupa.com/t/declaring-variables/17188/5 "2003-04-03T07:12:51Z")

</div>

ahh thanks a lot

the real reason I needed this was because I had to make a game for an assignment for school. Everyone basically uses Visual Basic and there was marks in the theory part for “meaningful variable names” and “data types”.
