tags:

views:

513

answers:

3

A Flex components values are initlized by init methord. In an application flow, How to refresh a mxml component data value ; as init is callled at the start up it self only.

eg. of mxml componet may be as simple as button label or text as complex as repeater whose data provider is a web service ( means a fresh quesy should be made to pull the data and refresh the dataprovider of repeater )

A: 

If the dataprovider is a collection or an array it will update itself as items are added to or deleted from the collection. You can listen to the CollectionEvent.CollectionChange event to see when a collection changes.

I'm not really sure what you mean though? Are you on about binding?

Jon
Arrays does not fire events upon internal changes, e.g. when an item is pushed on to it and thus your statement is incorrect. However, ArrayCollection does fire events and should be used just as you say.
macke
A: 

If you want to re-init the whole control, you could create an "reset" event and have the handler for the reset execute the same behavior as the init code.

That's the best I can do without more details...

Aaron Saunders
could provide me a template code a mxml repeater component or any component. this would clarify the idea
A: 

you should create yourself setters and getters for the properties you want to modify and a refresh is required afterwards. for example:

private var _tmp : String = '';
public function set tmp(val : String) : void {
      this._tmp = val;
      this.doOtherDataRefreshNeeded();
}
public function get tmp() : String {
      return this._tmp;
}

and this way, everytime the code that uses this component and needs to update it's tmp property. the setter will be called and in there a lot of other stuff can happen beside assigning the value.

for simple mxml components as texts and inputs, use bindings {} for their data values. those should update as soon as the data changes. if not, call .invalidateNow() method on them to force update.

TheBrain
This is actually not really best practices. The setter may well be called ten, hundred or even thousands of times during one frame which would mean multiple unnecessary calculations being done. Best practices is to call one of the invalidation methods (possibly invalidateProperties) and then during the commit phase (commitProperties) do the actual work involved with the refresh. This guarantees that while the invalidation method may be called multiple times during one frame, the actual work is only executed once.
macke
I think invalidateProperties is the default way to get better control on UI components