PDA

View Full Version : classes that are defined within functions?


prettymuchbryce
04-12-2007, 11:49 PM
Sorry I've posted so may threads in this forum. I just am trying very hard to learn actionscript and thus far you all have been very helpful.

Ok heres my question. I have an event handler function in which i declare a new movieclip() class referece inside of it, however; when I try to access the reference from another function it tells me its undefined. If I declare the reference outside of the function everything works fine though. Why does it do this and how can I fix it?

EDIT: I figured out that if I just make an array and store my movieclips in tehre that it doesnt matter which funciton I create them in. I guess that is the problem but I am still curious as to why this happens.

senocular
04-13-2007, 03:42 PM
when you define variables in a function block, they are local to that function and are not accessible outside of that function. This keeps function variables separate from other environment variables to prevent conflict. If you need something to be accessible outside of a function as well as inside a function, you need to defined it first outside the function.