Declaring Variables

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.

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… :slight_smile:

playamarz :player:

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:

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

pom :slight_smile:

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 :slight_smile:

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”.