-
[F8] Extracting radiobutton data from loop
Hi
Cant find the answer to this and im sure its dead easy but..Sorry im a newbie
Basically i have a radio button based quiz (at present with only 10 questions (so i could do this by hard coding - but the numbers may increase in future so i want to be able to loop through)
Basically each radiogroup has 3 answers with a value of 0, 1 or 2 - i need to get this value for each one, allocate it and the use further down the line
I have created an array to store these values (and that works when manually accessing as opposed to looping)- so basically it is just the right hand variable that i am not accessing properly whilst in the loop- have posted the code below for help - thanks in advance (n.b. this is AS1 and is triggered on a submit buton)
code:
on (release)
{
for(i=0; i<amountOfQuestions; i++)
{
//howAnswered[i]= ([i]_radioGroup.getData());
howAnswered[i] = eval(i+"_radioGroup.getData()");
//the bits above are a few of my attempts to access data - both duff
//everything else seems ok
//allocate the values
if (howAnswered[i]==0)
{
never++;
}
else if (howAnswered[i]==1)
{
sometimes++;
}
else if (howAnswered[i]==2)
{
always++;
}
}
gotoAndStop("frame2");
}
-
Pixel Artéést
so the if (howAnswered[i]==0) part of the code isn't working?
have you tried tracing howAnswered[i] after it's set to make sure you're setting it to the right value?
Try that (if that's what you meant) then work backwards to the source. I'm here to help!
-
Hi
Nope the part to allocate the variable was working fine. the bit that wasnt working was howAnswered[i] = eval(i+"_radioGroup.getData()");or the like - basically the right hand side was dodgy code/syntax.
I have now sussed a way to do it though -so i will post below for anybody else having the same issue. (probably not the most elegant solution - but it works). thanks for having a look anyway - much appreciated.
Working code below
code:
on (release)
{
for(i=0; i<amountOfQuestions; i++)
{
testMe=i+"_radioGroup";
trace(testMe);
//access the answers
//need to use eval to convert the string value to a path
howAnswered[i] = eval(testMe).getData();
//allocate the values
if (howAnswered[i]==0)
{
never++;
}
else if (howAnswered[i]==1)
{
sometimes++;
}
else if (howAnswered[i]==2)
{
always++;
}
}
gotoAndStop("frame2");
}
-
Pixel Artéést
glad you sorted it.
I should have spotted it!
It's also a good idea to use []'s instead of eval().
so eval("word"+i) would be ["word"+i]
If it's the left hand of an argument/statement you need to add this/_root/_level0 depending on the variables location, for example;
_root["word"+i] = "blah blah";
this["word"+i] = "blah blah";
and remember to leave the fullstop/period off the end of the _root and this's.
-
Thanks for the tip
Hi
Thanks for the tip - i had thought [] was only of use for defined arrays. Afraid im a designer - not a programmer - and am still trying to get my head around all of this -cheers again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|