10 Replies Latest reply on Jul 28, 2010 12:07 PM by kerry@rocknlearn

    Some Button Questions (AS2.0)

    kerry@rocknlearn

      I made a coloring book game in AS 2.0 (I did it this way so that I could put individual pieces of code for various buttons - there are around 50). I based it off a tutorial I found online. It works really well. These are the codes I used:

       

      In a top layer, I have just in frame 1 (there is only one frame in the whole thing):

      _root.fillColor = 0xFFFFFF;

       

      Each colorable part of the picture is a movie clip with a button inside, and each of those buttons has the following code:

      on (press) {

      color = new Color(this);

      color.setRGB(_root.fillColor);

      delete color;

      }

       

      And then I have two color buttons they can "dip" their pointer into, then they can click on the colorable areas and color them. The code for the color buttons is:

      on (release) {

      _root.fillColor = 0xC71E07;

      _root.brush.gotoAndStop(8);

      }

       

      Note: the hex code there is for the red button; it's different for the other color.

       

      Anyway, so this all works really well. What I need now are two buttons that I have NO idea how to make.

       

      Button 1: A "show answer" button that pops up a little graphic showing what their picture should look like. I know how to do this in AS 3.0 (I would just have the object fly in from off-stage on the button press), but not in 2.0. One thing I tried was to have it skip to a different scene or even just a different frame in which that object exists in place. The issue there is that it causes the coloring the user has done to disappear.

      Button 2: A "clear board" button that resets the whole thing. I've tried using the gotoandPlay(1) action with this button, but it doesn't do anything.

       

      Any help would be much appreciated. Thanks.

        • 1. Re: Some Button Questions (AS2.0)
          kglad Adobe Community Professional & MVP

          show what code you would use in as3 and i'll translate to as2.

          • 2. Re: Some Button Questions (AS2.0)
            kerry@rocknlearn Level 1

            to make the object fly in?

             

            answers_but.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);

             

            function fl_ClickToPosition(event:MouseEvent):void

            {

            answersflyin.x = 230.00;

            answersflyin.y = 187.50;

            }

             

            where "answers_but" is the instance name of the "show answers" button and "answersflyin" is the instance name of the graphic that shows the answer and then the coordinates there are where I want it to appear on the screen.

            • 3. Re: Some Button Questions (AS2.0)
              kglad Adobe Community Professional & MVP

              in as2, that would be:

               

              answers_but.onRelease = fl_ClickToPosition;

               

              function fl_ClickToPosition()

              {

              answersflyin._x = 230.00;

              answersflyin._y = 187.50;

              }

               

               

              • 4. Re: Some Button Questions (AS2.0)
                kerry@rocknlearn Level 1

                and I would add that to a actions layer, or to the button actions itself?

                • 5. Re: Some Button Questions (AS2.0)
                  kerry@rocknlearn Level 1

                  That works, except that the answer graphic disappears as soon as I let go of the button. I had the same issue when I just went into the button and put the answer graphic in place on the "down" and "hit" frames of the button.

                   

                  EDIT: Actually, it didn't work. I had forgotten to undo the other fix I mention there, so it was still half-working from that. When I just did what you said in an actions layer, it didn't work.

                  • 6. Re: Some Button Questions (AS2.0)
                    kglad Adobe Community Professional & MVP

                    if your as3 code would work, then the code i suggested would work.

                     

                    if the code i suggested doesn't work you probably have a reference problem to, at least, one of the objects.  use the trace() function to check.

                    • 7. Re: Some Button Questions (AS2.0)
                      kerry@rocknlearn Level 1

                      Do I add the code you suggested to the button's actions, or to an actions layer, as I would in AS3?

                       

                      What I posted from AS3 is from the code snippets thing, and it definitely works. Also, I'm not sure how to do the trace thing.

                      • 8. Re: Some Button Questions (AS2.0)
                        kglad Adobe Community Professional & MVP

                        the code should be attached to a frame where your objects exist.  what does the following show:

                         

                        trace(answers_but)
                        answers_but.onRelease = fl_ClickToPosition;

                         

                        function fl_ClickToPosition()

                        {

                        trace(answersflyin);

                        answersflyin._x = 230.00;

                        answersflyin._y = 187.50;

                        }

                         

                         

                        • 9. Re: Some Button Questions (AS2.0)
                          kerry@rocknlearn Level 1

                          Putting the code you gave me into my AS2.0 project, I get the following errors and no output:

                          Scene=Scene 1, layer=buttons, frame=1, Line 4     Statement must appear within on handler

                          Scene=Scene 1, layer=buttons, frame=1, Line 2     Statement must appear within on handler

                          Scene=Scene 1, layer=buttons, frame=1, Line 1     Statement must appear within on handler

                          This is the code I put on the button, just in case maybe there is some problem with it:

                          trace(show)

                          show.onRelease = fl_ClickToPosition;

                           

                          function fl_ClickToPosition()

                          {

                               trace(Answer);

                               Answer._x = 822.90;

                               Answer._y = 187.50;

                          }

                          (in this movie, the button to show answers is called "show" and the graphic that shows the answer is called "Answer")

                           

                           

                          I put this into another game I made in AS3.0 (the one I'm having drag-drop issues with) and it gives the following compiler error:

                           

                          Scene 1, Layer 'Actions', Frame 1, Line 93 1119: Access of possibly undefined property onRelease through a reference with static type flash.display:SimpleButton.

                          If I just keep my code as-is (on the AS3.0 one) but add the trace function to the answersflyin, it works the same as it did before and the output says [object MovieClip].
                          Thanks for all the help, by the way. I have no idea what I'm doing; learning on the job.

                          • 10. Re: Some Button Questions (AS2.0)
                            kerry@rocknlearn Level 1

                            I solved it!

                             

                            I made the animation 3 frames long.

                             

                            The first frame has just the background and a still shot of the colorable area and is set to just play.

                            The second frame has all of my game.

                            The third frame has all of the game, plus the answer in place.

                             

                            The show answers button goes to frame 3, the clear board button goes to frame one. Voila!