PDA

View Full Version : Listbox queries


jib
06-20-2007, 04:10 AM
Hey guys,
Another simple question (I hope):
Have a listbox in flash, and not really sure how to refer to it's contents in action script. I'll just simplify the situation:

Labels:
[Red, Yellow, Blue]
Data:
Select Multiple:
false
Change Handler:
Lbox_1

I'd like to start the clip, with "Red" automatically highlighted, but can't really figure out how to use this.
Tried: Lbox_1 = "Red" (But of course this doesn't work - I was kind of expecting it would be slightly more complicated)

Also I'd like to be able to make statements like:
If (Lbox_1 == "Yellow") {...such and such}

But something tells me I am not communicating properly with the list box... Do I have to give the Listbox an instance name also?

I am guessing it will be something simple like:
if (Lbox1._value == "Yellow") {such and such};
But the trial and error thing isn't going so well today!

Thanks in advance - for your assistance and patience,
Cheers,
Jib

_Aerospace_Eng_
06-20-2007, 04:33 AM
Yes you do but Lbox_1 is supposed to be a function not the value it gets.

jib
06-20-2007, 05:15 AM
A function... Really? Not sure I completely understand- (this is a bit new for me)

I was under the impression the Listbox was an object... and the selected Label(s) was a propety of this object, which I could refer to and change with only one or two lines of code.

Can/(How can) I do this?

Sorry I wouldn't be asking these q's if I could find them in online tutorials, but I can't find any on the topic.

jib
06-20-2007, 05:29 AM
Been playing with this sort of idea:

Lbox_1.select(Red)
trace(Lbox_Inner.getselecteditem())

or:
Lbox_1.select("Red")
trace(Lbox_Inner.getselecteditem())

but keep getting response: undefined
Am I headed about this the right way?

jib
06-20-2007, 05:45 AM
Figured out the first half...

trace(Lbox_1.getValue()) lets me figure out what is selected.

Is there a code that will highlight a value in the listbox for me?
Ie: lets say I want Red to be highlighted when the clip starts...

_Aerospace_Eng_
06-20-2007, 05:54 AM
Is Lbox_1 the instance id of the list box? If it is then you can use
Lbox_1.selectedIndex = 0;
This will highlight the first option, setting that to 1 will highlight the 2nd option.

jib
06-20-2007, 06:53 AM
Is Lbox_1 the instance id of the list box? If it is then you can use
Lbox_1.selectedIndex = 0;
This will highlight the first option, setting that to 1 will highlight the 2nd option.

Thanks again for your help,

It looks right to me, but it didn't work... (Flash MX - but I wouldn't expect this to be the problem).
I have checked the instance is named correctly, and used:
_root.Lbox_1.selectedIndex = 0;
just to be sure, but no luck.

I uploaded the .FLA:
http://www.freespace.com.au/filehosting/12726
If anybody thinks they know what's wrong, would be much appreciated.

Thx again _Aerospace_Eng_

Cheers,
Jib

_Aerospace_Eng_
06-20-2007, 09:54 PM
Things changed in Flash 8 and Flash CS3. Everything I've tried would work with a Flash 8 or Flash CS3 list box component but won't with a Flash MX component. Since I don't have Flash MX I can't help you. All I can tell you is read the Flash help file as it tells you how to implement a lot of things. selectedIndex is the syntax you are looking for. It just may be implemented differently in Flash MX. Here is the livedoc for Flash MX on selectedIndex on list components.
http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00002521.html

Good luck.

jib
06-21-2007, 01:26 AM
Hmm... well, looks like I'll be upgrading then.

Thanks so much for your help.