Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Extensions and Plugins > Components

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 4.50 average. Display Modes
Old 03-16-2005, 09:48 PM   #1
JoeyClams
Registered User
 
Join Date: Nov 2002
Posts: 35
Question V2 ComboBox: Default value based on selectedItem not selectedIndex

Ok I can't find any doco on this and it's driving me crazy. Anyone know how you specify the default value for the V2 ComboBox component based on the selectedItem when you don't know the selectedIndex? Here's my scenario:

I have a hardcoded combobox called "dd_names" with 50 names in it. I'm returning a dataset into Flash via a SQL query, and onload I need the dd_names dropdown to default to the value of the name returned in the dataset. So if the query returns "Tom" I need the dropdown to default to "Tom."

I tried setting dd_names.selectedItem = "Tom" and dd_names.value = "Tom" and these don't work. The ComboBox just defaults to the first item in the list.
However, if I use the selectedIndex property and set dd_names.selectedIndex = 3, the ComboxBox doesn't default to the first item in the list but shows the appropriate item. This doesn't help because I don't know the selectedIndex being returned from the query - I only know the selectedItem. Anyone know how to do this???

thxInAdv
JoeyClams is offline   Reply With Quote
Old 06-12-2006, 06:46 PM   #2
FlashBulb
Friar Tuck's eternal meal
 
FlashBulb's Avatar
 
Join Date: Oct 2003
Location: Ontario, Canada
Posts: 386
Default

Here's what I did:

ActionScript Code:
function findIndex(whichArray:Array, whichItem:String) {     var ret_value = "value not found";     for(var i in whichArray)     {         if(whichArray[i] == whichItem)         {             ret_value = i;         }     }     return ret_value; }; my_cb.selectedIndex = findIndex(my_cb.data, "Tom");

I realize you posted over a year ago, but I was just having the same problem. Hopefully this will help someone else!
FlashBulb is offline   Reply With Quote
Old 06-18-2006, 10:48 PM   #3
Shaka
Registered User
 
Join Date: Mar 2006
Posts: 4
Default

It helped for me almost 3 years after
Thanks from Argentina
Shaka is offline   Reply With Quote
Old 04-11-2007, 11:05 PM   #4
dogstar
New Member
 
Join Date: Oct 2004
Posts: 22
Default

Helped me now Thanks from UK
__________________
_______________________________
Hågen Landsem
www.k9design.co.uk
dogstar is offline   Reply With Quote
Old 10-30-2007, 10:31 AM   #5
YosiDov
Registered User
 
Join Date: Oct 2007
Location: Jerusalem, Israel
Posts: 4
Unhappy Work BUT

This works well when the options of the Combobox are inserted in the component parameters window (Data and Label), but I have an #include with a external text file that have lines and lines of "addItem", in this case the "my_cb.data" is undefined, do someone can help me with this?

Thanks from Jerusalem!
YosiDov is offline   Reply With Quote
Old 10-30-2007, 01:04 PM   #6
FlashBulb
Friar Tuck's eternal meal
 
FlashBulb's Avatar
 
Join Date: Oct 2003
Location: Ontario, Canada
Posts: 386
Default

You can use the my_cb.labels array instead of the my_cb.data one.

ActionScript Code:
Array.prototype.findIndex = function(whichItem:String):Number {     var ret_value = "value not found";     for(var i in this)     {         if(this[i] == whichItem)         {             ret_value = i;         }     }     return ret_value; }; trace("Index: " + my_cb.labels.findIndex("Tom"));

I also made it a prototype, I like this way better.
FlashBulb is offline   Reply With Quote
Old 10-30-2007, 01:14 PM   #7
YosiDov
Registered User
 
Join Date: Oct 2007
Location: Jerusalem, Israel
Posts: 4
Default Index: undefined

Index: undefined
YosiDov is offline   Reply With Quote
Old 10-30-2007, 01:16 PM   #8
FlashBulb
Friar Tuck's eternal meal
 
FlashBulb's Avatar
 
Join Date: Oct 2003
Location: Ontario, Canada
Posts: 386
Default

Hmm, you're loading in the labels from a text file - maybe they're not loaded yet? Is your ComboBox given the instance name my_cb?
FlashBulb is offline   Reply With Quote
Old 10-30-2007, 01:32 PM   #9
YosiDov
Registered User
 
Join Date: Oct 2007
Location: Jerusalem, Israel
Posts: 4
Default

1) I load the variables from an external as file, the variables are loaded with an #include line, I just try making a delay to see if maybe variables are not loading yet, nothing change.

2) My Combobox name is "product", I change the name in the relevant parts in your script

Code:
Array.prototype.findIndex = function(whichItem:String):Number
{
    var ret_value = "value not found";
    for(var i in this)
	{
        if(this[i] == whichItem)
        {
            ret_value = i;
			trace(i)
        }
    }
    return ret_value;
};
trace("Index: " + product.labels.findIndex(MiValor));

function EscribeEsto(){
	MiValor = MiValor + chr(Key.getCode());
	product.selectedIndex = findIndex(product.label, MiValor);
        product.open();
        product.text = MiValor;
}
product.addEventListener("keyDown",EscribeEsto);
I'm trying the following: when the Combobox (product) is in focus and the client types in his keyboard I want the text from the Combobox (MiValor) to show the typed text and my options scrolls automatic until the option that is the most similar (by A-B-C) to the typed text.
YosiDov is offline   Reply With Quote
Old 10-30-2007, 02:47 PM   #10
FlashBulb
Friar Tuck's eternal meal
 
FlashBulb's Avatar
 
Join Date: Oct 2003
Location: Ontario, Canada
Posts: 386
Default

You only need one argument in the new 'prototype' way - the Array is known already, because you call it as a function of that Array.

ActionScript Code:
product.selectedIndex = product.labels.findIndex(MiValor);

EDIT: I just saw the bottom part of your post - this way doesn't search for the closest match based on the starting letters.

Are you still getting 'Index: undefined' traced?

Last edited by FlashBulb; 10-30-2007 at 02:50 PM.
FlashBulb is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.