?
Solved

Listener Objects and XML List Components

Posted on 2005-02-26
2
Medium Priority
?
248 Views
Last Modified: 2010-04-03
I was given some code here that allowed me to populate a list component with my XML.  That thread and code is here:

http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21314467.html

Now, I'm trying to understand how my listener can know how to associate the item that was clicked on in the list with a different item in my xml. Here is my listener object:

var nodes:Array = _root.songList.firstChild.childNodes;

for(var i:Number = 0; i < nodes.length; i++){
      var children:Array = nodes[i].childNodes;
      _root.song_list.addItem(children[0].firstChild.nodeValue, children);
}
      var listener:Object = new Object();
      listener.change = function(evt:Object):Void
{
      var data:Object = evt._root.song_list.selectedItem.data;
};
_root.song_list.addEventListener("change", listener);

It's watching change to the list componet with the instance name of song_list.  The code I have works, I'm just trying to understand it so I can implement it in a slightly different way elsewhere.  I need to understand how the listener know which node was selected so I can access other associated data for that node (if I'm saying that correctly).
0
Comment
Question by:Aspirin99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Buffon earned 2000 total points
ID: 13412395
you get in you function as parameter "evt:Object", this event object contains properties (properties that contain information about the event) for example:
evt.target      <<----         a reference to the component instance broadcasting the event


so in this case, instead of:
evt._root.song_list.selectedItem.data
you can write:
evt.target.data


evt.target is a cell you update and it has properties like data and label.
0
 
LVL 1

Author Comment

by:Aspirin99
ID: 13412527
I'm just not making the connection. I'll study some more and see if I can ask the question better.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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