Listbox Tutorial - help with a variation

http://www.kirupa.com/developer/mx/listbox.asp

I downloaded this excellent tutorial and I’m trying to modify it to my needs. Problem is, the second I start getting into the code, it no longer works.

Here’s is what I’m trying to accomplish…

When an item is clicked in the list box, I’d like it to open a URL.

And a second variation to that would be to have multiple URLs assigned to each listbox item. A radio box would determine which URL to use.

Any help would be much appreciated.

Thanks

Can you show me the code you tried?

pom :slight_smile:

Yes I’ll post the code - if you promise not to laugh. :slight_smile:

BTW, I’m just learning MX - jumping in from Flash4. I’m having a lot of errors just with formating and syntax.

Step 1 - Add items to listbox (I don’t think I have the syntax correct for the data)

list.addItem(“ABC”, artisturl(“http://www.abcmartinfry.com”));
list.addItem(“A-Ha”, artisturl(“http://www.a-ha.com”));

Step 2 - (I know this is completely wrong)
function launchsite() {
list.getSelectedItem(artisturl);
[getURL(artisturl, “_blank”)];
}

Step 3 -
list.setChangeHandler(launchsite);

Hey, I’m not laughing at all, as a matter of fact you’re almost there :slight_smile:

Let’s have a look at your mistakes:[list][]list.addItem(“ABC”, artisturl(“http://www.abcmartinfry.com”));
I’m guessing you’re putting artisturl because I put Date in the tute. The thing is, you have to declare a Date object that way. But this is very specific. In your case, all you need is the string containing the URL.
[
]The launchSite function has to take as a parameter the current component (let’s call it “c”). Then you need to get the “data” part from the selected item, which is here the second argument you put in the addItem command. And then you getURL that URL.[/list]So if you have a listbox called list on the scene, you’ll have to put that kind of code:

list.addItem("ABC", "http://www.abcmartinfry.com");
list.addItem("A-Ha", "http://www.a-ha.com");
function launchSite(c){
	var j = c.getSelectedItem().data;
	getURL(j,"_blank");
}
list.setChangeHandler("launchSite");

Cheers.

pom :cowboy:

Woohoo!!!

I have been trying to accomplish this task forever.

I’m going to work on the next variation and see if I can get it. I’m going to have multiple URLs per item and see if I can get the different data based on a radio button or popup (URL, CDs, Vinyl, DVD).

I really need to learn MX actionscripting. <sigh>

Thank you so much!

  • Lex

Good luck. Post back if you need help. And remember that the “data” parameter can be an array…

pom :beam:

Thanks for the tip. I’ll have to conquer the understanding of arrays next. :slight_smile:

Here is the first version so far. This is nothing fancy - it just matches my website: http://www.djlex.com/club80s_artists.html

I’ll make a standalone version that my listeners can download. That will have a little more ‘flare’.

Quick question about XML. There is link that I can use to retreive the currently playing song for my webcast in XML format. I read something about Flash not being able to retrieve data across domains.

Does this mean I wouldn’t be able to use Flash to display my currently playing song?