http://matkat.tringali.org/misc/VisualFUN/Visualizer/Visualizer.html
I have a partially working AutoComplete for comboBoxes working on this. but I’m having lots of trouble for when you don’t make a selection from the DropDownList.
Here’s a way to test it:
click on FUN1’s A comboBox. type in " - ", you’ll see the only choice is -ON.
now don’t click on the choice in the list, just press Enter.
now, go back to that same ComboBox, and click the arrow to open it, and you’ll only see -ON as the choice. The dataProvider has been deleted
Go to another ComboBox and click the arrow without typing to see the list of values that should be there.
Here is the code that I’m using for this functionality.
//in the FUNSModule class file:
A_CB.addEventListener(MouseEvent.MOUSE_DOWN, getCurrentIndex);
A_CB.textField.addEventListener(Event.CHANGE, getEntry);
A_CB.addEventListener(Event.CHANGE, getChoice)
//A_CB.textField.addEventListener(ComponentEvent.ENTER, checkEntry)
//A_CB.addEventListener(MouseEvent.MOUSE_DOWN, setCurrentIndex)
A_CB.editable = true;
/*
private function checkEntry(event:ComponentEvent)
{
CB_UTIL.checkEntry(event, currentIndex)
}
private function setCurrentIndex(m:MouseEvent)
{
currentIndex = CB_UTIL.setCurrentIndex(m);
}
*/
private function getCurrentIndex(m:MouseEvent)
{ CB_UTIL.getCurrentIndex(m); }
private function getEntry(e:Event)
{ CB_UTIL.getEntry(e); }
private function getChoice(e:Event)
{ CB_UTIL.getChoice(e); }
And now the CB_UTIL class file
package
{
import fl.events.ComponentEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.controls.TextInput;
import fl.controls.ComboBox;
import fl.controls.BaseButton;
import flash.text.TextField;
import flash.display.MovieClip;
import fl.data.DataProvider;
public class CB_UTIL extends MovieClip
{
private static var cbList:Array
private static var currentIndex:Number;
public static var initDP:DataProvider;
private static var initArray:Array;
public function CB_UTIL()
{
trace ("CB_UTIL() constructor");
currentIndex = 0;
//initDP = new DataProvider();
initArray = new Array();
cbList = new Array();
}
public static function getCurrentIndex(m:MouseEvent)
{
trace (" *****************GetCurrentIndex")
//records selectedIndex when user clicks, and also records current dataProvider of selected ComboBox;
var obj = m.currentTarget;
var i:Number;
var s:String;
var n:String;
currentIndex = obj.selectedIndex;
initDP = new DataProvider();
trace ("initDP: ",initDP);
if (initDP.length > 0)
{
initDP.removeAll();
}
initArray = [];
for (i = 0; i < obj.length; i++)
{
s = removeSpaces(obj.getItemAt(i).label);
n = obj.getItemAt(i).label;
initArray.push({norm:n, trunc:s});
initDP.addItem(obj.getItemAt(i));
}
}
public static function getEntry(e:Event)
{
//reads user's input, and finds match in initArray.
//shows a dataProvider with only things that match
trace ("\r *********************** getEntry()\r")
var i:Number;
var t:String = TextInput(e.currentTarget).text;
var cb:ComboBox = ComboBox(e.currentTarget.parent);
var temp:Array = [];
var tempDP:DataProvider = new DataProvider();
t = removeSpaces(t).toUpperCase();
for (i = 0; i < initArray.length; i++)
{
var q:String = initArray*.trunc.substr(0,t.length).toUpperCase(); //convert every initArray element into an upperCase string, that is equal in length to the user's input
if (t == q)
{
trace ("Found a Match:", initArray*.norm);
temp.push(initArray*.norm);
}
}
//create temporary DataProvider for CB
for (i = 0; i < temp.length; i++)
{
tempDP.addItem( { data:temp*, label:temp* } );
}
//show the temporary DataProvider to the user with the filtered choices
cb.dataProvider = tempDP;
cb.rowCount = 17;
cb.invalidate();
cb.open();
}
public static function getChoice(e:Event)
{
//finds user's choice in initArray(created when you click on the CB)
//reloads the original dataProvider into the CB, and selects the index where user's choice was found.
trace ("\r ********************** getMouseChoice\r")
if (e.target.selectedIndex != -1)
{
var cb = ComboBox(e.target);
var i:Number;
var j:Number;
var choice:String;
choice = removeSpaces(cb.selectedItem.label).toUpperCase();
for (i = 0; i < initArray.length; i++)
{
var n:String = removeSpaces(initArray*.norm).toUpperCase();
if (choice == n)
{
cb.removeAll();
for (j = 0; j < initDP.length; j++)
{
cb.addItem(initDP.getItemAt(j));
}
cb.selectedIndex = i;
return;
}
}
}
}
/*
public static function checkEntry(event:ComponentEvent, currentIndex:Number)
{
var i:Number;
var cb:ComboBox = ComboBox(event.currentTarget);
var gap
cbList = [];
for (i = 0; i < cb.length; i++)
{
var n:String = cb.getItemAt(i).label;
//trace (n)
n = processString(n);
//trace (n)
cbList.push(n);
}
//trace (cb.text)
cb.text = processString(cb.text);
//trace (cb.text.substr(cb.text.length-4,cb.text.length))
for (i = 0; i < cbList.length; i++)
{
//trace ("cb.text is Not A Number: ",isNaN(parseFloat(cb.text)));
if ((isNaN(parseInt(cb.text)) == false) && (cb.text.substr(cb.text.length-4,cb.text.length) != "STEP") && (cb.text.charAt(0) != "+"))//dealing with number
{
//trace (" dealing with number");
//trace (cb.text, cbList*);
gap = (cbList[i+1] - cbList*)/2;
if ((parseInt(cb.text) - cbList*) <= gap) //if we typed 15, and cbList* = 14, select *
{
cb.text = "";
cb.selectedIndex = i;
return;
}
else if (i == cbList.length - 1)
{
cb.text = "";
cb.selectedIndex = currentIndex;
return ;
}
}
else //((isNaN(parseFloat(cb.text)) == true) || (cb.text.charAt(0) == "+")) //dealing with a string
{
//trace (" dealing with string")
//trace (cb.text, cbList*);
if (cb.text == cbList*)
{
trace (cb.text, cbList*);
cb.text = "";
cb.selectedIndex = i;
return;
}
else if (i == cbList.length - 1)
{
cb.text = "";
cb.selectedIndex = currentIndex;
return;
}
}
}
}
public static function setCurrentIndex(m:MouseEvent):Number
{
//trace ("MouseUP on ", m.target.constructor, m.target.parent)
if (m.target.constructor == TextField) //textField part of the ComboBox
{
return m.target.parent.parent.selectedIndex;
}
else if (m.target.constructor == BaseButton) //button part of the ComboBox
{
return m.target.parent.selectedIndex;
}
else //because we nested our ComboBoxes inside a FUNS module?
{
return m.target.selectedIndex;
}
}
*/
I’ve been stuck on this problem for over a week now,** it’s driving me completely crazy!!!** any help is appreciated. I’ve narrowed the problem down to when the user clicks outside the comboBox without selecting from the list, thus setting the SelectedIndex to -1.
[LEFT]
[/LEFT]