我创建了一个列表,但我不知道如何增加单元格的大小。 所以我遇到了这个问题:http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-6166126-569357/450-446/test2.png
你能解决这个问题吗?
这是我的代码:
package ca.xty.myUtils {
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import fl.controls.List;
import fl.controls.Button;
import flash.text.AntiAliasType;
import fl.data.DataProvider;
public class AutoComplete extends Sprite {
// These constant variables will be used in our event dispatches
public static const SHOW_LIST:String = "SHOW_LIST";
public static const MADE_CHOICE:String = "MADE_CHOICE";
// These variables will be used to get information back to our Document Class which is why they have a public declaration
public var aIndex:int;
public var noResult:String;
// These variables will hold the information contained in the parameters passed in the constructor
private var _passedArray:Array;
private var _txtWidth:int;
private var _txtHeight:int;
private var _whichProperty:String;
private var _btnTxtColor:Number;
// Display variables
private var acList:List;
private var acArray:Array;
private var listHeight:int = 100;
private var listHeightCalc:int;
private var searchBtn:Button;
private var sTerm:String;
private var acTxt:TextField;
// TextFormats
private var titleFormat:TextFormat;
private var topBtnFormat:TextFormat;
// Convenience variables for loops
private var i:uint;
private var len:uint;
public function AutoComplete(PassedArray:Array, WhichProperty:String, TxtWidth:int, TxtHeight:int, BtnTxtColor:Number = 0x000000) {
// Place the parameter values passed in the constructor into our private vars
_passedArray = PassedArray;
_txtWidth = TxtWidth;
_txtHeight = TxtHeight;
_whichProperty = WhichProperty;
_btnTxtColor = BtnTxtColor;
// Give our TextFormats some properties
titleFormat = new TextFormat();
titleFormat.size = 23;
titleFormat.font = "ARIAL";
titleFormat.leftMargin = 3;
topBtnFormat = new TextFormat();
topBtnFormat.color = 0x000000;
topBtnFormat.size = 40;
topBtnFormat.font = "ARIAL";
// Call the function to build the display
buildAC();
}
private function buildAC():void{
// This is the TextField users will type in what they want to search for
// It takes it's width and height from the variables passed in the constructor
// The event listener responds to any change in the TextField
var tf:TextFormat = new TextFormat();
var myFormat:TextFormat = new TextFormat();
tf.size = 50;
myFormat.size = 50;
tf.font = "Time New Roman";
acTxt = new TextField();
acTxt.defaultTextFormat = tf;
acTxt.x = -20;
acTxt.y = 0;
acTxt.width = 670;
acTxt.height = 120;
acTxt.type = "input";
acTxt.border = true;
acTxt.background = true;
acTxt.textColor = 0x000000;
acTxt.backgroundColor = 0xffffff;
acTxt.antiAliasType = AntiAliasType.ADVANCED;
acTxt.sharpness = 100;
acTxt.thickness = 100;
acTxt.addEventListener(Event.CHANGE, updateDisplay);
addChild(acTxt);
// Our Search Button
searchBtn = new Button();
searchBtn.x = 140;
searchBtn.y = 130;
searchBtn.width = 300;
searchBtn.height = 125;
searchBtn.label = "RECHERCHER";
searchBtn.setStyle("textFormat", topBtnFormat);
searchBtn.addEventListener(MouseEvent.CLICK, searchHandler);
addChild(searchBtn);
// The List component that will display the auto-complete results
// Notice it has the visibale property set to false
// It's event listener responds to a change, ie an item is clicked
acList = new List();
acList.setRendererStyle('textFormat',myFormat);
acList.x = -20;
acList.y = acTxt.y + acTxt.height;
acList.setSize(645, 0);
acList.visible = false;
acList.addEventListener(Event.CHANGE, listHandler);
addChild(acList);
}
// This is the function that fires when there is a change in the acTxt field
private function updateDisplay(e:Event):void{
// We set our variable sTerm to equal the value of the acTxt field
sTerm = acTxt.text;
// Set the sTerm to lower case
sTerm = sTerm.toLowerCase();
// Create an empty version of our acArray
acArray = new Array();
// Set the len variable to be that of the array we passed in through the constructor
len = _passedArray.length;
// Run a for loop to look through the array for items which match the sTerm
for(i = 0; i < len; i++){
// Create a variable to hold the first label item in our array and set it to be lower case
var firstLabel:String = _passedArray[i][_whichProperty].toLowerCase();
// Create a variable for the firstLetter using a sub string - the actual length of firstLetter will be determined by
// the length of sTerm so that firstLetter might really be first two letters...
var firstLetter:String = firstLabel.substr(0, sTerm.length);
// if the firstLetter var matches the STerm then we push corresponding item from the passed array into our acArray
if(firstLetter == sTerm){
acArray.push({label:_passedArray[i][_whichProperty], data:i});
}
}
// Once we've run through the whole array we calculate the List height
listHeightCalc = acArray.length * 20;
// if the calculated list height is greater than the variable listHeight then we set the height of the list to be listHeight ( our maximum height )
// otherwise we set the height of the list to the calculated height
if(listHeightCalc > listHeight){
acList.height = listHeight;
}else{
acList.height = listHeightCalc;
}
// Clear our our List
acList.removeAll();
// Use the new acArray as the data provider
acList.dataProvider = new DataProvider(acArray);
// Make the list visble
acList.visible = true;
// Dispatch the event that will make sure the list is on top of all the othe diaply items
dispatchEvent(new Event(AutoComplete.SHOW_LIST, true));
}
// This function handles the clicking of oneof the items in the List
private function listHandler(e:Event):void{
// Put the selected item's label in the acTxt field
acTxt.text = e.target.selectedItem.label;
// grab the data from the selected item and assign it to the aIndex variable
aIndex = e.target.selectedItem.data;
// Put the List's visibility back to false;
acList.visible = false;
// Dispatch the event to the Document class
dispatchEvent(new Event(AutoComplete.MADE_CHOICE, true));
}
// This function handles a click of the Search Button
private function searchHandler(e:MouseEvent):void{
// Reset the acArray to a nice new empty array
acArray = new Array();
// Reset the List's visible property to false;
acList.visible = false;
// Assign the contents of the acTxt field to our sTerm variable
sTerm = acTxt.text;
// Set the sTerm to lower case
sTerm = sTerm.toLowerCase();
// Loop throught the array and put matching items into our acArray
for(i = 0; i < len; i++){
var firstLabel:String = _passedArray[i][_whichProperty].toLowerCase();
trace("firstLabel: " + firstLabel);
trace("sTerm: " + sTerm);
if(firstLabel.indexOf(sTerm) != -1){
acArray.push({label:_passedArray[i][_whichProperty], data:i});
}
}
// Check to see if the calculated height for the List is bigger than the maximum height we set and build the List accordingly
listHeightCalc = acArray.length * 20;
if(listHeightCalc > listHeight){
acList.height = listHeight;
}else{
acList.height = listHeightCalc;
}
// If our acArray's length is greater than one we want to use the List to show you the result options
// Once again we dispatch the event that will make sure the List is on the top of the diaply heap
if(acArray.length > 1){
acList.removeAll();
acList.dataProvider = new DataProvider(acArray);
acList.visible = true;
dispatchEvent(new Event(AutoComplete.SHOW_LIST, true));
// If our acArray's length is equal to 1, no need to set up the List, just stick it in our acTxt field
// This time we dispatch the event that will display the results
}else if(acArray.length == 1){
acTxt.text = acArray[0].label;
aIndex = acArray[0].data;
dispatchEvent(new Event(AutoComplete.MADE_CHOICE, true));
// If there are no results from our search, we set the aIndex variable to -1, create our noResults string and dispatch the event to display that result
}else{
aIndex = -1;
noResult = "No Results for " + acTxt.text;
dispatchEvent(new Event(AutoComplete.MADE_CHOICE, true));
}
}
}
}
答案 0 :(得分:1)
如果要增加列表单元格的高度,请使用
acList.rowHeight = 50;