Titus
Titus

Reputation: 4627

How do I add an event listener to a button inside a tab navigator (flex 4.5)?

I have a tab navigator defined in MXML, with two tabs. In each tab, I have some buttons. I have used ActionScript to add event listeners to all the buttons, and they work for the buttons that are visible (and in the currently "active" tab) when I load my Flex 4.5 AIR application.

However, I get an AIR error for the event listeners attached to the buttons in the second tab. Here's the crucial part of the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

And when I test out my application, sure enough, there are no event listeners attached to the buttons in the second tab.

How can I fix this?

Upvotes: 0

Views: 242

Answers (1)

Felipe
Felipe

Reputation: 11887

I think you need to set creationPolicyto 'all' on your TabNavigator. This is because, by default, Flex only initializes the screens that are actually visible. If you set your TabNavigator creationPolicy attribute to "all", all elements will be initialised, even if they are not visible.

Upvotes: 2

Related Questions