Groups | Blog | Home
all groups > flash actionscript > september 2005 >

flash actionscript : List Component frustration - please help


Schiavoni
9/11/2005 10:23:56 PM
Ok, getting a little frustrated wit the LIST component.

I have a list component (my_list). I can easily populate the list
(data/label) dynamically.
Then, I attached this code to the list component:

on (release) {
getSelectedItem1 = this.getItemAt(this.selectedIndex).label;
getSelectedItem2 = this.getItemAt(4).label;
trace(getSelectedItem1);
trace(getSelectedItem2);
}

Why do I get "undefined" when I'm trying to grab the value from the
selectedIndex, but if I use the same type of line and specifiy the index, I get
the value I expect.

Can anyone help - show me what I'm doing wrong. It's really annoying me.

Thanks ... Carl
I
jsmgvs
9/11/2005 10:34:58 PM
Try

getSelectedItem1 = this.my_list.getItemAt(this.selectedIndex()).label;

or

getSelectedItem1 = this.my_list.getSelectedItem().label

getSelectedIndex() is a method -- needs () -- and is applied your listbox.

Hope this helps!
Schiavoni
9/12/2005 9:15:31 PM
Unfortunately, neither suggestion worked. Really has me baffled since
"getSelectedItem1 = this.getItemAt(4).label;" works just fine. You'd like all
I'd have to do is get the selectedIndex or selectedItem ... but alas, I've
tried a dozen variations in the attempt.

I do appreciate the response though. Just wish I oculd figure this seemingly
simply process out. Maybe I'm just need to think of it from a different
direction.

Carl
myIP
9/13/2005 12:00:00 AM
??if I use the same type of line and specifiy the index, I get the value I
expect.?

So you know the syntax is correct and it works as expected. But when you put
the code in somewhere else it no longer works. Just from what you have said I
would have to say it?s a scope issue as jsmgvs also assumes. In Flash, if you
go to the Actions Panel (F9) you will see icons above where the code would be.
If you click on the Target icon (a circle with cross-hairs) it will help you
find a path to a movieClip.
I have a List component on stage with an instance name of ?myList?. If I put
the code below on my button (movieClip) it retrieves what the user has selected.

on (release)
{
trace(this._parent.myList.getItemAt(this._parent.myList.selectedIndex).label);
}
AddThis Social Bookmark Button