AS3 How to add eventListener to a Listbox Item?

Posted on 2009-04-23
Medium Priority
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(e.target.data);
	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
  • 2

Accepted Solution

biyik earned 2000 total points
ID: 24219189
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: "+myList.selectedItem.data)

That's it!

Author Closing Comment

ID: 31573938
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.

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 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