PDA

View Full Version : var?


dominick100
04-29-2002, 05:05 PM
Easy Question:
I've been through a couple of Flash books (How to do everything.. & Foundation ActionScript), so I at least have a limited background, and thought I had the basics down.

However, in the 1st chapter of Moock's Definitive Guide, he's expressing variables as "var x = 1".
I've always just expressed this as "x = 1"

I looked up "var" in Flash's reference section, and it looks to do the same thing. is there any difference in expressing variables in these 2 ways? Is is just to make all lines that set variables easily recognizable?

I tried searching the forum, but I didn't really see anything explaining this. I'm just starting to get into the meat of Flash here, and don't want to start off setting things up incorrectly.

Thank you.

notsofast
04-29-2002, 05:29 PM
I believe "var" creates a variable that only exists inside the block of code (between "{" and "}") where it was created. Saying "x = 1" will create x as a member of the _root object or "this" object, depending on where that line of code is placed.

jimburton
04-29-2002, 05:55 PM
notsofast is right and if you start writing a lot of functions with loops in that are executed repeatedly, using var so that the actionscript interpreter discards the variables it doesn't need can save you a bundle of memory and help performance. If you use it outside of a function it doesn't have any effect.