priyank
priyank

Reputation: 4724

flex how to refresh already created view

How can I refresh view after a certain event?

I have a view which contains multiple groups. I want to show or hide some groups.

onCreationComplete() or initialize() method works only at the beginning of the view creation.

Upvotes: 2

Views: 6849

Answers (2)

shaunhusain
shaunhusain

Reputation: 19748

I personally don't like the answer that says to call invalidateDisplayList (sorry no offense Nate nothing personal). I feel it's too vague and doesn't explain what this does under the hood and furthermore you shouldn't have to call it directly in cases such as the one explained in the OPs question. You can simply create booleans that are bindable for each of the groups you'd like to show/hide then in the event handler set those booleans to the appropriate value and if they are bound to the visible and include in layout properties of the containers those containers will internally call invalidateDisplayList after calling set visible and consequently commitProperties.

This is basically what happens under the hood as I understand it: The way this works is values aren't committed or used to update the display until the next frame this way it doesn't get bogged down doing unnecessary layout calculations. So you update the bindable property which fires an event which triggers a notification in the listener (in this case a function that sets the property on your control), that in turn passes along the value to the control which sets an internal flag to update the property and calls invalidateProperties. When it hits the next frame redraw it sees that the properties flag is dirty (true) and then calls commitProperties, this computes/sets the appropriate values (possibly also invalidating then "fixing" the size using invalidateSize() and measure()) and calls invalidateDisplayList, then during the same frame it sees that the display list flag is dirty so it calls updateDisplayList, here it uses the values of the properties to draw appropriately.

You should also be able to achieve this using states, which add or remove children from the display list based on an array of "actions" for each state.

Upvotes: 1

Nate
Nate

Reputation: 2936

Try invalidateDisplayList() on the view

Let me know if that doesn't do the trick and we'll try some other tricks.

Upvotes: 5

Related Questions