First, let's see how to add data to the list component and how to display the mouse-clicked objects.
1. Static generation method:
My_list.additem ("Labe" L, data );
Instance: create a file and drag the list component to the scenario. Modify the Instance name of the List component to "my_list" and add the following code in the first frame: system. usecodepage = true;
VaR my_list: MX. Controls. List;
My_list.additem ({label: "Gordon", data: 123 });
My_list.additem ({label: "UK", data: 456 });
My_list.additem ({label: "China", data: 888 });
If you want to test the effect, you can add more in the as code...
Example:Click play/hide MediaHttp://www.taoshaw.com/flash/list/lesson1.swf
2. Dynamic generation method (adding data to the list by loading XML ):
Instance: create a file and drag the list component to the scenario. Modify the Instance name of the List component to "my_list" and add the following code in the first frame: // solve the garbled problem...
View other original tutorials related to the list component:
[Url = http://www.taoshaw.com/taoshaw/article.asp? Id = 1376] use the list component to create a QQ friend robot >>> [/url]
[Url = http://www.taoshaw.com/taoshaw/article.asp? Id = 1375] Using menubar to load XML to build a Windows-like menu >>> [/url]
[Url = http://www.taoshaw.com/taoshaw/article.asp? Id = 1356] freely modify component animation effects (openduration, openeasing) >>> [/url]
[Url = http://www.taoshaw.com/taoshaw/article.asp? Id = 1355] set the text font in Flash (using textfield. getfontlist ();) >>> [/url]
[Url = http://www.taoshaw.com/taoshaw/article.asp? Id = 1299] list component usage summary> [/url]
System. usecodepage = true;
// Define doc_xml as an XML class;
VaR doc_xml: xml = New XML ();
// Ignore spaces.
Doc_xml.ignorewhite = true;
Doc_xml.onload = _ root. xmlload;
// The initial file is "Renming. xml "...
_Root.doc _ xml. Load ("Renming. xml ");
Function xmlload (){
VaR childnodes = This. firstchild. childnodes;
// Prevent the addition of the base program. The meaning of this sentence is to make the XML loaded by my_list different each time.
_ Root. my_list.removeall ();
For (var I: Number = 0; I <childnodes. length; I ++ ){
_ Root. my_list.additem (childnodes [I]. Attributes. Label, childnodes [I]. Attributes. data );
}
}
3. click the button to load different XML files. // When the place name definition button is triggered, place names are loaded...
Diming. onrelease = function (){
_Root.doc _ xml. Load ("diming. xml ");
};
Renming. onrelease = function (){
_Root.doc _ xml. Load ("Renming. xml ");
};
Shijian. onrelease = function (){
_Root.doc _ xml. Load ("Shijian. xml ");
};
4. Call the object after the mouse clicks and call the data of the object: _ root. onenterframe = function (){
Show_txt_label = _ root. my_list.selecteditem.label;
Show_txt_data = _ root. my_list.selecteditem.data;
};
My_list.selecteditem.label; my_list.selecteditem.data;
Examples of steps 2-4 in section 1 are as follows:
Http://www.taoshaw.com/flash/list/lesson2.html
Section 2: related operations on the list component.
1. Delete all items in the list component list: _ root. my_list.removeall ();
Method to delete all items in the list.
Calling this method modifies the data provider of the List component. If you share the data provider with other components, those components will also be updated.
When you press the button, the following code clears all items in the list component.
2. Delete the selected project:
List. removeitemat () var N: Number = _ root. my_list.selectedindex;
_ Root. my_list.removeitemat (N)
3. Select the last and next Methods: selindex = _ root. my_list.selectedindex;
_ Root. my_list.selectedindex = (selindex = 0) | (selindex = undefined )? _ Root. my_list.length-1: selIndex-1 );
// Let the scroll bar follow
_ Root. my_list.vposition = selIndex-2;
// Subtract one item each time. If the project is the first item or undefined item, 0 is the first item in the Flash algorithm, and length-1 is the last item.
If (selindex = 0 | selindex = undefined ){
_ Root. my_list.vposition = _ root. my_list.length-1;
Example 1-3 in section 2:
Demo:
Http://www.taoshaw.com/flash/list/removeAll.html
// The XML file loaded in this file is in the previous step. The same below...
4. Add the data in one list to another: // Add the data on the left to the list on the right...
VaR newobj = new object ();
_ Root. my_list.addeventlistener ("change", newobj );
J = 0;
Arr_3 = new array ();
Arr_4 = new array ();
// Determine whether to repeatedly select ================
VaR label_arr: array = new array ();
// Check whether duplicate label Values exist.
Function checkrepeat (v ){
VaR isrepeat: Boolean = false;
VaR Len: Number = label_arr.length;
For (VAR I = 0; I <Len; I ++ ){
If (V = label_arr [I]) {
Isrepeat = true;
Break;
}
}
Return isrepeat;
}
// ======================================
// Click to select a single item
Newobj. Change = function (Num ){
VaR newobject = num.tar get. selecteditem;
Arr_3 [J] = newobject. label;
Arr_4 [J] = newobject. Data;
If (checkrepeat (arr_4 [J]) = false ){
_ Root. my_listother.additem ({data: arr_4 [J], label: arr_3 [J]});
Label_arr.push (arr_4 [J]);
} Else {
Already_select.gotoandplay (2 );
}
J ++;
};
5. click the button to add all items in a list to another list. Show_db_menu = function (){
If (_ root. my_list.selectedindex> = 0 ){
_ Root. my_list.selectedindex = undefined;
}
// This is the key. If an option already exists, cancel the selection so that the for loop below can be used.
For (I = 0; I <(_ root. my_list.length); I ++ ){
VaR selindex = _ root. my_list.selectedindex;
_ Root. my_list.selectedindex = (selindex = undefined )? 0: selindex + 1 );
// If no option exists, the value 0 is 1 in the Flash incrementing algorithm starting from the first option. The value is added until the end of the com_box.length algorithm.
VaR newobject_menu = _ root. my_list.selecteditem;
Arr_3 [J] = newobject_menu.label;
Arr_4 [J] = newobject_menu.data;
If (checkrepeat (arr_4 [J]) = false ){
_ Root. my_listother.additem ({label: arr_3 [J], data: arr_4 [J]});
Label_arr.push (arr_4 [J]);
}
J ++;
}
};
Step 4-5 in section 2.
Instance: http://www.taoshaw.com/flash/list/onetoother.html
6. Add the icon var labelname = ["taosha net", "Sand", "taoshaw", "taolang taosha"] to the text in each line of the List component of flash.
VaR ico_mc: array = new array ();
List. iconfield = "icon"; // sets the icon identifier in the object array, which is not a link attribute.
For (VAR I = 0; I <4; I ++ ){
Ico_mc.additem ({label: labelname [I], icon: "ICO" + I}); // If You Want to unify the icons, write them as "ico0 ", modify the link property of a video in the library.
}
List. dataprovider = ico_mc;
Instance: http://www.taoshaw.com/flash/list/listico.html
7. List component beautification.
About the beautification of the List component style (including modifying the scroll bar style ):
Instance:Click play/hide MediaHttp://www.taoshaw.com/flash/listmeihua.swf
The Code is as follows: (list Instance name: "cllist") Import MX. Controls. List;
Import MX. Controls. scrollclasses. scrollbar;
Scrollbar. Prototype. scrolltrackname = "mc1 ";
Scrollbar. Prototype. thumbmiddlename = "mc2 ";
Scrollbar. Prototype. thumbbottomname = "mc2 ";
Scrollbar. Prototype. thumbtopname = "mc2 ";
Scrollbar. Prototype. thumbgripname = "MC3 ";
Scrollbar. Prototype. uparrowupname = "mc4 ";
Scrollbar. Prototype. uparrowovername = "mc4 ";
Scrollbar. Prototype. uparrowdownname = "mc4 ";
Scrollbar. Prototype. downarrowupname = "mc5 ";
Scrollbar. Prototype. downarrowovername = "mc5 ";
Scrollbar. Prototype. downarrowdownname = "mc5 ";
VaR cllist: List;
Cllist. setstyle ("borderstyle", "NONE ");
// Uparrowupname is in the normal (normal) Status of the up and left buttons. The default value is scrolluparrowup.
The status of the uparrowovername to move up and to the left button. The default value is scrolluparrowover.
Uparrowdownname indicates the push status of the up and left buttons. The default value is scrolluparrowdown.
The downarrowupname is normal when the button is down or right. The default value is scrolldownarrowup.
Downarrowovername: the slide status of the down and right buttons. The default value is scrolldownarrowover.
Downarrowdownname: The push status of the down and right buttons. The default value is scrolldownarrowdown.
Scrolltrackname is a component used for the track (background) of the scroll bar. The default value is scrolltrack.
Scrolltrackovername is a component used to slide the background of a rolling track. The default value is undefined.
Scrolltrackdownname is a component used to hold the background of a rolling track. The default value is undefined.
Top and left of the thumbtopname scroll box (slider. The default value is scrollthumbtopup.
The middle (Extensible) part of the thumbmiddlename slider. The default value is scrollthumbmiddleup.
Bottom and right of the thumbbottomname slider. The default value is scrollthumbbottomup.
Thumbgripname is the starting point displayed on the slider. The default value is scrollthumbgripup.
8. For details about how to set the list component style, refer:
Http://doc.51windows.net/FlashHelpSC? Url =/flashhelpsc/SC/usingcomponents/04_components91.html
Http://doc.51windows.net/FlashHelpSC? Url =/flashhelpsc/SC/usingcomponents/04_components98.html
Http://www.5460.net/gy5460/jsp/article/dispArt.jsp? Dnum= 535270
List component style attributes
Backgroundcolor background color
Backgroundalpha background color transparency value ranges from 0.00 ~ 1.00
Whether userollover uses the mouse to list each item. The result is true or false.
The background color userollover is
Valid when true
The text color userollover is
Valid when true
In the alternatingitemcolors list, set the interval background color attribute to 2 colors.
Color, the background color of one item and the background color of the next item
Color option text color
Selectioncolor the background color of the selected item
Textselectedcolor text color of the selected item
Textindent option text indent distance
Selectionduration the gradient speed of the selected item. The background color of the selected item changes
The speed of the value in selectioncolor. The gradient effect value ranges from 0 ~ The greater the value of 5000, the slower the gradient speed.
Borderstyle border style none solid inset
Outset
Bordercolor border color
Borderthickness the Border width value ranges from 0 ~ 20
Whether dropshadowenabled displays the projection true and false attributes.
Shadowdistance: The number of valid values when the projection size of dropshadowenabled is true.
The value ranges from 0 ~ 20
Three properties in the shadowdirection Projection Direction: Left right center
Dropshadowcolor: The color of the projection.
9. How can I remove the edge of the List component?
// My_list is the Instance name of the List component in the scenario.
_ Root. my_list.setstyle ("borderstyle", "NONE ");
10. Specify the color of the line in the alternate mode for the list component:
// Directly paste this line... Is a fixed mode...
_ Global. Styles. scrollselectlist. setstyle ("alternatingrowcolors", [0xff00aa, 16777215])
11. Make the list component support HTML tags:
Http://www.stonemx.com/blog/archives/2006/200681803148.html
12. Use dataprovider to add a data source to the list component. The data source comes from an array;
VaR my_list: MX. Controls. List;
VaR myarray: array = new array ();
Myarray. Push ({label: "Fuling", data: 1 });
Myarray. Push ({label: "fengdu", data: 2 })
Myarray. Push ({label: "Chongqing", data: 3 })
My_list.dataprovider = myarray;
// Note: When you use dataprovider to add data to a component, the second time you use this command, all data for the first time will be replaced. Additem is not used.
13. Use event scheduling to return the List Value:
VaR my_list: MX. Controls. List;
VaR my_array: array = new array ();
My_array.push ({label: "Fuling", data: 1 })
My_array.push ({label: "fengdu", data: 2])
My_list.dataprovider = my_array;
VaR lo: Object = new object ();
Lo. Change = function (eventobj: Object): void {
Trace(eventobj.tar get. selecteditem. Data)
}
My_list.addeventlistener ("change", LO)
Go
Http://www.taoshaw.com/taoshaw/article.asp? Id = 1299