views:

2761

answers:

4

hi, im trying to getting auto complete working and i can do so fine when i just create an array in my mxml and then just initialize an arrayCollection at the top of the file in the initialize keyword.

However i want to populate the arraycollection from a webservice but i cant seem to get it;

im my application tag i have the following

creationComplete="init()"
initialize="data2 = new ArrayCollection(data1);"

then in my init method;

    private function init():void 
{
userRequest.loadWSDL(wsdlUrl);
userRequest.getAllCountries();
}

//this is called when i get a result from userRequest.getAllCountries();

 private function getAllCountriesResult(e:ResultEvent):void 
    {
    data1 = new Array(e.result);
        }

however my text box is not getting any value.

Anyone with ideas?

+1  A: 

first off, Array is not Bindable so changing the variable data1 will have no knock on effect.

The arrayCollection is bindable.

So presumming that the result (e.result) is actually an array (you should check this when debugging) then you could do the following

[Bindable]
priavte var ac : ArrayCollection;

then inside you're getAllCountriesResult function.

ac = new ArrayCollection(e.result);

then anything that has is dataprovider set to the var ac will be updated.

If you wish to update a text value inside a textArea or similar then you should listen for the change event in the arrayCollection and take the appropriate action then.


from your additional points below (just edit your original question)

I take it the autocomplete your talking about is the autocomplete text input box from adobe exchange area as a normal text box doesn’t take an arrayCollection. If you posted some code it may make it easier to help you. Preinitialize, then initialize, then creationComplete, then applicationComplete (this is the order they get called in).

If your using the component I’m thinking of, check out http://www.websector.de/blog/2008/04/30/quick-tip-avoid-issues-using-adobes-autocomplete-input-component-using-flex-3/ It appears it may have some issues with flex 3, so check out http://blogs.adobe.com/flex/2006/09/component_autocomplete_text_in.html .

kenneth
A: 

still not working, im using a webservice to populate the arrayCollection, any ideas? also does creationComplete get called before initialize and if not can i call functions from my intialize? cheers

combi001
Please edit your original post instead of adding further details as answers.
David Hanak
A: 

i actually get the data and autoComplete working however with one problem, the first element in the array is always present at load time in the input box. When i delete it and start typing it works fine but this is not what i want.

Any ideas?

combi001
How about adding a blank entry to the beginning of the list in getAllCountriesResult()?
David Hanak
A: 

Try this:

private function getAllCountriesResult(e:ResultEvent):void 
{
   data2.source = new Array(e.result); // or data2.source = e.result as Array
}

Make sure data2 is already initialized as a ArrayCollection.

As for AutoComplete, I'm trying to work things out myself.

SS Kim