Why do I need to use Static Variables in an AS include file?
This question comes in from an anonymous reader who commented on one of my other postings about includes in ActionScript.
Maybe you should explain why i need to typein a include scenario?
public STATIC var test:String;
He went on to say that he was looking around for hours and could not find this issue addressed. The answer is that variables defined in an included file do not need to be static. I've used includes with non static variables and other code that doesn't create variables.
The Flextras watermarking code uses includes to help minimize the code difference between our developer edition and the unlimited domain edition. No static variables are found in there. I also once used an include for a hard coded data provider to help simplify the main file. It was a list of a hundred (or so) countries and I got tired of paging up and down through the list to move from the top of the file to the bottom.
That is not to say you can't use static variables in the include file. I've never tried it but see no reason why you wouldn't be able to.
Anon asked a follow up question that I thought I would address too:
Looking around for hours and not finding much explanation as to why i need to use STATIC. Is it because the included file is only loaded once!?
Included files are not included once. They are included everywhere you use them. As best I imagine it the compiler does a cut and paste from the include file into your main file.
Anon's question inspired the topic for the most recent Flextras Friday Lunch presentation, all about static variables. Check out the recording here, and feel to stop by any Friday at 1PM EST to ask me questions in person.
If that doesn't work, e-mail me.





There are no comments for this entry.
[Add Comment] [Subscribe to Comments]