Authentication when WS is called in Flash _ 5: dataProvider Problem

Source: Internet
Author: User
In the example completed yesterday, I found a problem. dataProvider does not know why and adds some objects with unknown data types. For example, I have customized an array for the datagrid as a data source, as follows:
Var tt: Array = new Array ();
Tt = [{name: "JimLee", sex: "F" },{ name: "lwanchen", sex: "X"}];
DbGrid. dataProvider = tt;
After binding the array to dbGrid, follow my ideas.
Trace (dbGrid. dataProvider. length );
2 should be returned because the value is assigned to dbGrid. the tt array of dataProvider has only two elements, but the fact is that the value returned by flash may be 8, 9, or 2. If a loop is written, follow dbGrid as follows. elements in dataProvider:
For (var I: int = 0; I <dbGrid. dataProvider. length; I ++ ){
Trace (dbGrid. dataProvider [I]. name );
Trace (dbGrid. dataProvider [I]. sex );
}
In addition to the [{name: "JimLee", sex: "F"}, {name: "lwanchen", sex: in addition to "X"}], several undefinded values are returned !!
Where is the problem?
After reading the help documentation, the source file of dataProvider, and so on, I finally found the crux of the problem: if the number of array elements provided is smaller than the height of the dataGrid component/rowHeight (dataGrid attribute, Row Height ), flash will automatically fill the remaining number of rows with undefinded objects.
Once you know the reason, you can do it. modify the code below (you only need to modify it in ):
1. added the resultRowNum variable.
Var resultRowNum: Number = 0;
2. assign a value to resultRowNum in the GetArray_3 method:
Function GetArray_3 (myDB ){
ResultRowNum = myDB. length;
Gb_main.dataProvider = myDB;
Trace (gb_main.dataProvider.length );
}
3. process the change event of the DataGrid component gb_main. If the DataGrid is a new row, make the variable resultRowNum equal to the maximum value of data in the DataGrid component gb_mai.
Ls_mdc = new Object ();
Ls_mdc.change = function (evt ){
Var tgb: objectincluevt.tar get;
If (tgb. selectedIndex> (resultRowNum-1 )){
ResultRowNum = tgb. selectedIndex;
}
}
Gb_main.addEventListener ("change", ls_mdc );
4. Modify the processing function of the button dbBind3_bt and submit the DataGrid component gb_mai to WS:
This. dbBind3_bt.onPress = function (){
// Trace (gb_main.dataProvider [1]);
Trace (gb_main.dataProvider.length );
Var I: Number = 0;
Var tCar: Array = new Array ();
Trace (resultRowNum );
For (I = 0; I <resultRowNum; I ++ ){
TCar. push (gb_main.dataProvider [I]);
Trace (tCar [I]. model );
}
// TCar = gb_main.dataProvider;
/* For (I = 0; I <(tCar. length/2-1); I ++ ){
Trace (tCar [I]. model );
}
*/
Var op_8: PendingCall = myws. GetArray_4 (tCar );
Op_8.onResult = GetArray_4;
}
In this way, you can. Unfortunately, if the MM company provides a function similar to trim and crops out the undefinded element of the Data Type in dataProvider, it will be much more convenient, so that we will not do so much useless work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.