Swiz ‘Could not get a reference to class’ Gotcha

I’ve been implementing Swiz framework in my most recent Flex project. It’s worked great so far, but this one error sidetracked me for an hour or so:

"Could not get a reference to class for YourEvent.YOUR_EVENT_TYPE. Did you specify its package in SwizConfig::eventPackages?"

Obviously, the first thing to do when receiving this message is to make sure you specified the event package in SwizConfig::eventPackages. Once that’s confirmed, you ensure that the event has been imported, then try cleaning your project(s).

At this point it starts getting frustrating and you could easily start going off the rails moving code around and making crazy modifications. Before you get to that point, make sure you’re actually dispatching the event somewhere in your code. If you aren’t, then the event isn’t included when the application is compiled. Since it never gets included, Swiz cannot get a reference to it when the application runs.

This can happen when refactoring and moving events around a little at a time. If you’re like me, you do a little testing along the way to make sure everything continues to work properly. That’s when you can wind up in a case where you may be listening for an event that you haven’t yet written the dispatch code for.

It may seems like an occurrence that may happen once in a blue moon (Mmmm…Blue Moon), but it’s already happened to me twice in the span of a couple of weeks.

5 thoughts on “Swiz ‘Could not get a reference to class’ Gotcha

  1. Thanks for this.

    I’ve seen the come up in my projects before but couldn’t find out why…dang smart compiler 🙂

Comments are closed.