Your problem is that .vimrc is sourced first, before the autocommand is fired. So when the if statement is reached, the variable doesn't exist yet.
How best to accomplish what you're shooting for depends on what it is that you want to do. Your message doesn't really make that clear, but if you provide some more details about your ultimate goal, people can probably offer suggestions. Also, just as minor comments on your code: You don't need leading colons on the commands in a Vim script. The idiomatic way to source a particular script based on file type is to save it as an ftplugin. See `:help ftplugin` and, more specifically, `:help ftplugin-name` for details on the different ways to accomplish this.
pgpWLhe9tGxRz.pgp
Description: PGP signature
