• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3847
  • Last Modified:

Flex ComboBox data initialization complete event

I have an XML data bound to a Flex combo box.
I'd like to get notified when the combobox is completely initialized with data and the first item of the combobox is in valid selected state.(so that I can do other needed action automatically assuming the first item is selected upon creation)

        <mx:ComboBox dataProvider="{blogNameAry}" width="100%"
              add="onBlogCBInit()"
              change="onBlogChange()"
              id="blogCB">
        </mx:ComboBox>

Whenever the selection is changed from the combobox, I get correct notificaiton with valid state of the selection.(onBlogChange). But right after the combobox is created, I cannot get the selected data(in this case the first one with index 0). In above example, onBlogCBInit() is called but the current selection is INVALID(meaning you cannot read the text content of the selected item).

I've tried with even {add, initialized, creationComplete} event, but they all behaves the same. Upon the event trigger, I don't have the valid data for the selected item.

How do I achive this initial selection only once when the combobox is completed?
0
shahnweb
Asked:
shahnweb
  • 4
  • 2
2 Solutions
 
julianopolitoCommented:
valueCommit - Dispatched when values are changed programmatically or by user interaction.
0
 
julianopolitoCommented:
also you could use "addedToStage", this one is better because it happens only once if the control is not removed and readded to the stage
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
This is just a suggestion not sure if this works also but try and let me know the result.

In the creationComplete call a method in that method just call blogCB.open(); followed by a blogCB.close(); then I think u must have the data ready to retrieve and use.

Let me know if there is some kind of jerk or flicker when u do all this. Thank you.



0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
shahnwebAuthor Commented:
I have 5 items in the CB, and valueCommit gets called 5 times (only 3 of them reads valid data from index 0)

addedToStage is better. It gets called 2 times and the 2nd one gets valid label from index 0.

creationComplete with open() close() trick does not work.

So far the best way is use addedToStage with label length check( != 0), but why does this get called twice?  Any other suggestion?

0
 
julianopolitoCommented:
can you send me a working code , so I can verify that to you? The problem may be because of the binding ocurring late in the flow, but it all depends on the way you did it. If you can send working code with sample data, I can double check that for you. addedToStage should not be called twice, only once.
0
 
shahnwebAuthor Commented:
julianopolito, you are probably right this is timing problem for binding.

When I removed the code from onBlogCBInit() to mx:HTTPService's resultHandler code, I could achieve what I aimed at.  So I solved problem.  

addedToStage still gets called twice before the resultHandler gets called and at the very end of the entire code execution.  I use Flex Builder 2, and it could be a bug?  Are you using Flex 3?

Anyway, I found a solution, and would like to close this and honor your input.
0
 
julianopolitoCommented:
Thank you. I use both Flex 2 and 3. I'll make some tests here to verify what you are saying about the added to stage.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now