AS3 How to add eventListener to a Listbox Item?

Posted on 2009-04-23
Last Modified: 2013-11-12
Ok, I am trying to create a video player, with a listbox.
The videos will be loaded from an XML file into the ListBox, my listbox is called: "myList"

For now I am able to read the XML file and load the data into the listbox, that is already working fine, as you can see in the code below I am programatically adding Items to my listbox, what I need to do is to also add an onRelease event to each new Item, or maybe is onClick event, I don't know.  And that is exactly where I need your expertise.

I thank in advance to all of you guys who help me.

varloader:URLLoader = new URLLoader();

loader.addEventListener(Event.COMPLETE, onLoaded);

loader.load(new URLRequest("xml/videos.xml"));

function onLoaded(e:Event):void


	var mainData:XML = new XML(;

	if ( mainData )


		for each (var element:XML in mainData.children()) 


			myList.addItem( { label:element.@desc.toString(), data:element.@url.toString(), event } )




Open in new window

Question by:fsilva79
    LVL 6

    Accepted Solution

    You need to add a "change" event for listening for clicks on the list component:
    myList.addEventListener(Event.CHANGE, clickFunction);
    Now you can decide what to do when clicked:
    function clickFunction(e:Event):void {
    //let's play the selected video:
    trace("you have selected: "

    That's it!
    LVL 2

    Author Closing Comment

    I have no other words than Thank you!!!!!!
    I need an expert in AS3, urgently, how can I get in touch with you? small project probably will be just 10 or 20 lines of code.
    LVL 6

    Expert Comment

    You can send a message to emre -at- cancoskun .com  . I'm going to be available on saturday.
    See you!

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now