View Full Version : How do I add variables to a selection in a list component?? (ie: Links)
ScarletSniper
03-11-2008, 08:02 PM
Hi!!
Thanks for the random ActionScript texts, they were very helpful.
I do have another question, though. I created a list box with text variables (ie: Name1, Name2, Name3, etc.) and I would like it when you select a variable in a list box, it redirects the person to another frame in the scene, or another slide in the project.
Basically, my question is how do you add a variable to a selection in a list component?? The variable I'm looking for is to redirect the person to another frame in the scene, or slide in the project, for each variable.
I'd appreciate it if someone could help me out with this.
Thanks!!
sunlis
03-11-2008, 10:11 PM
if (listBox.getSelectedItem().label == "Name1") {
trace("Name1 selected");
}
You can put that in an onEnterFrame, onMouseUp, etc. It doesn't matter.
Make sense?
ScarletSniper
03-11-2008, 10:47 PM
Thanks for the info, I'll give it a try.
ScarletSniper
ScarletSniper
03-12-2008, 01:04 AM
if (listBox.getSelectedItem().label == "Name1") {
trace("Name1 selected");
}
Hi!!
I've tried this code on Frame 1 of my scene, but it doesn't do anything. Is there anything missing where my variable will link to another frame. I'm a newbie with ActionScript, so I need a little more help, if you don't mind. A WinZip file using the code would just be what I'm looking for, but if not, thanks for trying.
sunlis
03-12-2008, 01:47 AM
OK, try this. Just use a blank list for this example.
//adds two items to the list
listBox.addItem("Name1");
listBox.addItem("Name2");
//waits for the mouse button to be released
onMouseUp = function () {
//makes sure the mouse if over the list component
L = _xmouse > list._x;
R = _xmouse < list._x + list._width;
U = _ymouse > list._y;
D = _ymouse < list._y + list._height;
if (L && R && U && D) {
//checks the label of the selected item
if (listBox.getSelectedItem().label == "Name1") {
//go to a specified frame
gotoAndPlay("1");
} else if (listBox.getSelectedItem().label == "Name2") {
//and again, but for a different item
gotoAndPlay("2");
}
}
};
I added comments, to make it easier to understand.
inhan
03-12-2008, 02:12 AM
Put a List component in the library (not on the stage) and try the following script:
import mx.controls.List;
var L:List = createClassObject(List, "my_list", 0, {_x:50, _y:60});
L.addItem({label:"item 1", link:"link1"});
L.addItem({label:"item 2", link:"link2"});
L.addItem({label:"item 3", link:"link3"});
L.addItem({label:"item 4", link:"link4"});
var listener:Object = new Object();
listener.change = function(evtObj:Object) {
var link:String = evtObj.target.selectedItem.link;
trace(link);
// _root.gotoAndStop(link);
};
L.addEventListener("change", listener);
sunlis
03-12-2008, 02:36 AM
There, someone who's actually used list components before discovering this thread. lol ;)
ScarletSniper
03-15-2008, 11:37 AM
Thanks for helping me out, guys. Your information was just what I needed. I apologize for the lateness of my reply, but I've been working hard with Flash 8, creating an RPG.
Again, Thanks For All Your Help,
ScarletSniper
:)
inhan
03-15-2008, 05:05 PM
Anytime ;)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.