// you’re reading...

Asides

Flex Builder Protip: Import missing imports

Let’s say you’ve just pasted in a snippet of code, or loaded a file that is missing imports.  When you compile, you get errors and you’re stuck importing each definition by hand.  Flex Builder provides a bit of a hidden feature here to help you import your missing types:  next to each type that is missing, press control-space at the end of the missing definition. Flex Builder will put the import in automatically.
So, when you have:

var foo:AbstractConsumer;

put your cursor between the r and the ; and hit the hotkey. And yes, this is the same as the command to bring up code hints. And yes, Flex Builder should really provide a mechanism to bring in imports on paste…but between now and then, this should work just fine

Discussion

6 comments for “Flex Builder Protip: Import missing imports”

  1. It’s no use in multi-language OS,when I press the hot-key (Ctrl+Space?) In Windows Vista in Chinese,it’s will change my IME.:)

    Posted by Dada | December 18, 2008, 5:46 pm
  2. It’s really just the same hot-key to trigger content assist/intellisense/code hints/whatever you want to call it… use that and you’ll be fine :)

    Posted by David Zuckerman | December 19, 2008, 9:53 am
  3. you can also change vista’s hotkey to anything else…

    Posted by ryan | December 21, 2008, 12:05 pm
  4. Thanks for the post David. That is helpful and very non-obvious. I usually fix missing imports using content assist
    by triggering it when I type ‘var a:’ and finding the type in the list, so this will definitely save me a lot of extra typing.

    I will say it seems strange to me that it can do this but it doesn’t provide ‘proper’ quick fix hinting to let you know it can fix it for you. Also, in addition to generating imports for a cut/paste, it would be nice to have a ‘fix imports’ menu item which attempts to add missing imports, for the case when you open an existing file that is missing it’s imports.

    Posted by Kelly Davis | January 9, 2009, 4:51 am
  5. Is it just me or does this only work in .as files and not in .mxml files? (Same is true for ctrl-shift-O)

    Posted by Matthew | January 16, 2009, 10:01 am
  6. So Ctrl-Shift-O doesn’t work, however this import trick should work. The condition is that your MXML document must be syntactically valid. In the upcoming version of Flex Builder, we will be relaxing this requirement.

    Posted by David Zuckerman | January 16, 2009, 10:44 am

Post a comment