Skip to main content
avid_body16B8
Legend
May 21, 2019
Answered

icon in the list component AS3- Is it possible

  • May 21, 2019
  • 1 reply
  • 1678 views

I am wondering if there is a way to add icons in the list component.

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi, res.

    Something like this should do the trick.

    AS3 code:

    import fl.data.DataProvider;

    import fl.controls.List;

    var icons:Vector.<Class> = new <Class>

    [

         Square, // linkage name in the Library

         Circle,

         Triangle

    ];

    var i:int;

    var total:int;

    var totalNewItems:uint = 10;

    list.iconField = "iconSource";

    list1.iconField = "iconSource";

    // replace current items

    for (i = 0, total = list.dataProvider.length; i < total; i++)

         list.dataProvider.replaceItemAt({iconSource:icons[i % icons.length], label:"Item " + i}, i);

    // add new items

    for (i = 0; i < totalNewItems; i++)

         list1.dataProvider.addItemAt({iconSource:icons[i % icons.length], label:"Item " + i}, i);

    FLA download:

    animate_cc_as3_list_component.zip - Google Drive

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    May 21, 2019

    Hi, res.

    Something like this should do the trick.

    AS3 code:

    import fl.data.DataProvider;

    import fl.controls.List;

    var icons:Vector.<Class> = new <Class>

    [

         Square, // linkage name in the Library

         Circle,

         Triangle

    ];

    var i:int;

    var total:int;

    var totalNewItems:uint = 10;

    list.iconField = "iconSource";

    list1.iconField = "iconSource";

    // replace current items

    for (i = 0, total = list.dataProvider.length; i < total; i++)

         list.dataProvider.replaceItemAt({iconSource:icons[i % icons.length], label:"Item " + i}, i);

    // add new items

    for (i = 0; i < totalNewItems; i++)

         list1.dataProvider.addItemAt({iconSource:icons[i % icons.length], label:"Item " + i}, i);

    FLA download:

    animate_cc_as3_list_component.zip - Google Drive

    Regards,

    JC

    avid_body16B8
    Legend
    May 21, 2019

    JC you are amazing! This is exactly what I was looking for.

    Muito obrigada.

    MonoDev
    Participating Frequently
    June 24, 2021

    Hi, MonoDev.

     

    Sorry I didn't answer you the other time.

     

    Do you want to retrieve the icone name? On click?


    JC,

    No worries, yes this should be retrieve on a button click. I will be using the icon name/data such as "OFF" "ON" to indicate the status of a lightbulp as an example. I will be comparing the value of the icon to matched against a graphics name. If these two match in name, then I will be manipulating the graphic.

     

    public function retrieveLabel(e: MouseEvent): void {
    //trace(e.target.name);
    //list.selectedIndices = (selected);
    // Here based on the item selected in a combo box and the button name I press, I set up the icons for the list component
    if(_cb.selectedLabel == "FREEZE DRYING" && e.target.name == "LOADING"){

    for (i = 0, total = _list.dataProvider.length; i < total; i++)

    _list.dataProvider.replaceItemAt({iconSource:_fdLoadingIcons[i % _fdLoadingIcons.length], data:_fdArray[i], label:_fdArray[i]}, i);

    // here I would add an event listener to check the list component icon name/data. what do you think?

    _list.addEventListener(Event.ENTER_FRAME, iconData);
    }

    public function iconData(event:Event):void{

     

    //lets say I have a MovieClip named "2V357"

    // if an item in the _list has the name "2V357" and the icons is "ON", then I would control the MovieClip aperance.

     

     

     

    }