problem with creating RadioButton with as2

  • florian64
  • Born
  • Born
  • florian64
  • Posts: 2

Post 3+ Months Ago

Hi,


it's several days that I'm looking for a solution for my problem without finding it so I'm posting here my question.

I'm doing a quizz using RadioButton compoment.

I use the script below, which works perfectly for the first set of RadioButtons, but does not work so well for the following sets:

ActionScript Code:

Code: [ Select ]
function setRadioButtons(nRB) {
   //erasing the previous set of RadioButtons, if it exists
   var iRB:Number = 0;
   while (mcQuestion["rb"+iRB] != undefined) {
     mcQuestion.destroyObject("rb"+iRB);
     iRB++;
   }

   //creating a new set of RadioButtons
   for (var iRB:Number = 0; iRB<nRB; iRB++) {
     mcQuestion.createClassObject(RadioButton,"rb"+iRB,mcQuestion.getNextHighestDepth(),{groupName:"gpName"});
   }
}
  1. function setRadioButtons(nRB) {
  2.    //erasing the previous set of RadioButtons, if it exists
  3.    var iRB:Number = 0;
  4.    while (mcQuestion["rb"+iRB] != undefined) {
  5.      mcQuestion.destroyObject("rb"+iRB);
  6.      iRB++;
  7.    }
  8.    //creating a new set of RadioButtons
  9.    for (var iRB:Number = 0; iRB<nRB; iRB++) {
  10.      mcQuestion.createClassObject(RadioButton,"rb"+iRB,mcQuestion.getNextHighestDepth(),{groupName:"gpName"});
  11.    }
  12. }




for some reason, the RadioButtons of the following sets (question 2, question 3, etc...) are displayed on the top left of the windows.

It seems that the part of the code I use for erasing the RadioButtons doesn't work very well because when I try to debug the script, I can see that RadioButtons instances are still here, even thought they disappear from the screen.

ActionScript Code:

Code: [ Select ]
//erasing the previous set of RadioButtons, if it exists
   var iRB:Number = 0;
   while (mcQuestion["rb"+iRB] != undefined) {
     mcQuestion.destroyObject("rb"+iRB);
     iRB++;
   }
  1. //erasing the previous set of RadioButtons, if it exists
  2.    var iRB:Number = 0;
  3.    while (mcQuestion["rb"+iRB] != undefined) {
  4.      mcQuestion.destroyObject("rb"+iRB);
  5.      iRB++;
  6.    }



Do you know what happens here?

Thank you for your help.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I doesn't seem like your positioning the radio buttons on the creation of them so they are being place at point 0,0 or top left

try something like
ACTIONSCRIPT Code: [ Select ]
//creating a new set of RadioButtons
for (var iRB:Number = 0; iRB<nRB; iRB++) {
      mcQuestion.createClassObject(RadioButton,"rb"+iRB,mcQuestion.getNextHighestDepth(),{groupName:"gpName"});
 
   // Where ever you need it i'm going to say 10,10
   mcQuestion["rb"+iRB]._x = 10;
   mcQuestion["rb"+iRB]._y = 10;
}
 
  1. //creating a new set of RadioButtons
  2. for (var iRB:Number = 0; iRB<nRB; iRB++) {
  3.       mcQuestion.createClassObject(RadioButton,"rb"+iRB,mcQuestion.getNextHighestDepth(),{groupName:"gpName"});
  4.  
  5.    // Where ever you need it i'm going to say 10,10
  6.    mcQuestion["rb"+iRB]._x = 10;
  7.    mcQuestion["rb"+iRB]._y = 10;
  8. }
  9.  


this is untested but should get you pointed in correct direction

I don't know why you would want to remove the radio buttons and create new ones to begin with i usually just have the max number i would need for the longest question and with code hide/unhide and position the radios where i need them (if they need to be moved)
  • florian64
  • Born
  • Born
  • florian64
  • Posts: 2

Post 3+ Months Ago

thank you for your answer Scott. I forgot to copy down the part of the code positioning my RB, but even though it donly work for the first set of RB and then doesn't work anymore. Seems like I can't destroy the RB object totaly.

I will try your solution hehe :)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.