4 Replies Latest reply on Jan 26, 2009 9:21 AM by Rothrock

    Forcing a checkbox selection

    tatiana1 Level 1
      Hi all, I have a CheckBox within a MovieClip. If I physically place the MovieClip on the Stage and force the CheckBox inside it to be selected, I see it selected. If I use attachMovie to place the MovieClip on the Stage and I force the CheckBox to be selected, the checkmark doesn't appear, although a trace returns TRUE. Here's the code:



      The trace returns TRUE, but the CheckBox doesn't appear selected. What am I doing wrong?
        • 1. Re: Forcing a checkbox selection
          Gipoh Level 1
          Hi there,
          Maybe you have to use _root. before the mc. Will be something like this:

          _root.mc.chk.selected = true;
          trace(_root.mc.chk.selected);


          Creation site internet | Radins | Jeux Concours | Programme TV
          • 2. Re: Forcing a checkbox selection
            tatiana1 Level 1
            Same thing. When I trace it, it returns TRUE, so the value does get set normally. It just doesn't draw the checkmark on the screen.
            • 3. Re: Forcing a checkbox selection
              tatiana1 Level 1
              Anyone?
              • 4. Re: Forcing a checkbox selection
                Rothrock Level 5
                The problem is most likely that all the children of the movieclip aren't immediately available when you attach the clip. All the variables and objects on the main timeline of the movieclip are available, but the children objects aren't available until one frame has passed.

                If you try and trace the mc.chk.selected value without assigning it, you will see that it is undefined because until one frame has gone by nothing is defined in the child.

                By setting it to true you are creating a value for that one frame before it is defined. But as soon as the checkbox's code runs it will replace it with its default value of false. You can see this if you add this to the end of your code:

                onEnterFrame=function(){
                trace(mc.chk.selected);
                }

                First the code outside the onEnterFrame will execute and show the value "true" and then it will repeat with "false." In fact since the first time you are setting it there is no reason it even needs to be a Boolean. You can say:

                mc.chk.selected="Hello world!"

                And it will "work." The only think I know to do is to cheat.

                attachMovie("mc","mc",100);
                onEnterFrame=function(){
                mc.chk.selected = true;
                delete this.onEnterFrame;
                }

                There is also a component.doLater() method that you might think will work. But again the checkbox inside the clip doesn't yet know that it is a component so you can't use a component method on it until after one frame.