PDA

View Full Version : Component Question - listBox


vosgien
04-02-2003, 05:30 AM
Hi,
I've looked at the new components section and the tutes concerning customizing components, but I cannot fathom what I want to achieve, so I'll explain in the hope that some kindly soul can help me.

I am using a list box to load in a list of vars from a text file for a multiple choice quiz.
When an item is clicked on it is highlighted - so far so good. When a second or subsequent item is clicked it is hiighlighted, and the previous highlight disappears.That is the default action.

How can I adjust the component (or what code can I use)so that each item clicked stays highlighted ?

Cheers

Vosgien

hey, sorry guys I have just realised that this should be posted in the Components forum, I will not repeat(never had a cross post yet) it but hope that a moderator will move it. OK

CyanBlue
04-02-2003, 10:39 AM
Um... Will this be the same??? Will it be to know how to select multiple items without Ctrl key??? Or something totally different???

vosgien
04-02-2003, 10:50 AM
Hi Jason,
How you doing ?
In answer to your questions, the list box loads questions using LoadVars, a user selects as many items as he wants and Score is incremented by one for each item clicked, so, I want each item clicked to remain highlighted, so that he/she can see what they have already clicked on - clear ( probably not - lol!!!)

I have located the correct mc in the library - FSelectableItem - and so far I have managed to alter the code so that when an item is clicked, it's _visibilty is set to false, it will be a useful compromise, but not ideal - any suggestions very much appresciated

Cheers

Vosgien

tg
04-02-2003, 01:50 PM
somewhere buried in that list box is a label (in the selected item)...

one way you may be able to do it would be to create a method to change the background color of the label when a list item is selected.


of course cyanblue has a good point there, currently using the cntrl key alows you to select multiple items in the list, so find that code in the component, and modify it so that multiple items can be selected with out using the ctrl key.

vosgien
04-03-2003, 07:58 AM
Hi,
Well, I have been playing around with this for a while now, I have managed to achieve one or two quite spectacular results, and have gained a better understanding of components and the way they work, although opening the core developer folder is a bit like opening a can worms ( lol!!!)
Next question which doen't involve compenents at all, is, how do I alter the code below to load my .txt file in list format into an ordinary dyanamic text box. Is that possible ?

My txt file looks like this :

&name0=Question1 Page1 Range1&
&name1=Question2 Page1 Range1&
&name2=Question3 Page1 Range1&
&name3=Question4 Page1 Range1&
&name4=Question5 Page1 Range1&
&name5=Question6 Page1 Range1&
etc etc to 40 questions
&numQuestions=40&

and my Loadvars is:

myQuestions1 = new LoadVars();
myQuestions1.onLoad = addQuestions1;
myQuestions1.load("Questions1-40.txt");

function addQuestions1() {
for (var i=0; i<this.numQuestions; i++) {
nilForty.addItem(this["name"+i]);
}
}

Cheers

Vosgien

CyanBlue
04-03-2003, 08:11 AM
You just made me hungry... :D

Anyways... Try this code and see if this does the job for you... BTW, 'nilForty' is the name of the listBox instance, right???myQuestions1 = new LoadVars();
myQuestions1.onLoad = addQuestions1;
myQuestions1.load("Questions1-40.txt");

function addQuestions1()
{
for (var i = 0 ; i < Number(myQuestions1.numQuestions) ; i++) {
nilForty.addItem(myQuestions1["name"+i]);
}
}

vosgien
04-03-2003, 08:35 AM
Hi,
yes nilForty is the name of the listBox, BUT I want to load the txt file into an ordinary dynamic text box not a listBox.
That code doesn't do it - think I'll run a trace and try an find out why.
I think, from something I have read here, that I need to alter the txt file, but not sure how

Bon Appetite !

Vosgien

CyanBlue
04-03-2003, 08:44 AM
Um... Something like this??? Just create a dynamic text field with the instance name of 'qText' on the main timeline and check out the script...myQuestions1 = new LoadVars();
myQuestions1.onLoad = addQuestions1;
myQuestions1.load("Questions1-40.txt");
function addQuestions1()
{
for (var i = 0; i < Number(myQuestions1.numQuestions); i++)
{
qText.text += myQuestions1["name" + i] + "\n";
// nilForty.addItem(myQuestions1["name" + i]);

}
}

vosgien
04-03-2003, 08:50 AM
Hi,
yep, great, thanks Jason - think my error was giving the textBox a var name and not an instance name.
Its the little things............

Cheers

Vosgien

CyanBlue
04-03-2003, 08:55 AM
Yup... Usually that's how it is... :D

Just as a reminder for you... Do not use variable name box in FMX unless you are exporting your movie to F5... That variable name box is there for the backward compatibility, and you are not tasting the sweat juice of FMX with it... :p

Gotta go get some sleep... See ya...