8 Replies Latest reply on Jan 13, 2011 8:10 AM by Randall_Lanier

    CS5 AS3 MovieClip errors.

    Randall_Lanier

      I'm having an issue in scripting a MovieClip to play within a MovieClip. The outer MovieClip is a "Page" and on the page, you must click a button to play the second MovieClip, which is planned to remove the activating button, and play the MovieClip, stopping at the end, and presenting another button. I'm getting various error with different variations of the scripts.

       

      Here is the code for my MovieClips:

       

       

      package
           {
                 import flash.display.MovieClip;
                 import flash.events.MouseEvent;
       
                 public class Main extends MovieClip
                       {
                             var startPage:StartPage
                             var hillPage:HillPage;
                             var pondPage:PondPage;
                             var raft:Raft;
                             var sailPage:SailPage;
                             var raftButton:RaftButton;              
                 public function Main()
                       {
                              startPage = new StartPage();
                              hillPage = new HillPage();
                              pondPage = new PondPage();
                              raft = new Raft();
                              sailPage = new SailPage();
                              addChild(startPage);
         
      //add event listeners
      startPage.hillButton.addEventListener(MouseEvent.CLICK,onHillButtonClick);
      startPage.pondButton.addEventListener(MouseEvent.CLICK,onPondButtonClick);
      hillPage.hillBack1.addEventListener(MouseEvent.CLICK,onBackButtonHillClick);
      pondPage.pondBack1.addEventListener(MouseEvent.CLICK,onBackButtonHillClick);
      pondPage.raftButton.addEventListener(MouseEvent.CLICK,onRaftButtonClick);
      pondPage.exploreButtonRight.addEventListener(MouseEvent.CLICK,onExploreButtonRightClick);
      pondPage.raftButton.addEventListener(MouseEvent.CLICK,playAnimation);

       

      //add event handlers
      function onHillButtonClick(event:MouseEvent):void
        {
         addChild(hillPage);
         removeChild(startPage);
        }
      function onPondButtonClick(event:MouseEvent):void
        {
         addChild(pondPage);
         removeChild(startPage);
        }
      function onBackButtonHillClick(event:MouseEvent):void
        {
         addChild(startPage);
         removeChild(hillPage);
        }
      function onBackButtonPondClick(event:MouseEvent):void
        {
         addChild(startPage);
         removeChild(pondPage);
        }
      function onRaftButtonClick(event:MouseEvent):void
        {
         removeChild(raftButton);
         flash.display.MovieClip.raft(event:MouseEvent, playAnimation);
        }
      function playAnimation(event:MouseEvent):void
        {
             raft.play();
        }
      function onExploreButtonRightClick(event:MouseEvent):void
        {
         addChild(sailPage);
         removeChild(pondPage);
        }
      }
      }
      }

       

       

       

      Any assistance is greatly appreciated. Thanks.

        • 1. Re: CS5 AS3 MovieClip errors.
          Ned Murphy Adobe Community Professional & MVP

          Often errors are due to set up issues, so your best bet is to provide the compete error messages that you are getting.  And before you do that, go into your Flash Publish settings and select the option to Permit Debugging.  This can add other useful info to the error messages.

          • 2. Re: CS5 AS3 MovieClip errors.
            Randall_Lanier Level 1

            Here is the error Flash is giving me.

             

            1119: Access of possible undefined property raft through a reference with static type Class.

             

             

            I'm not sure what Flash is saying, so If you could help you, I'd greatly appreciate it.

             

             

            What I'm trying to get done is that when you click a button that says "RAFT" on it, a raft descends from the top of the screen to a certain point, the "RAFT" button is removed, and a new button shows up that says "EXPLORE" and when clicked, the raft moves off the right side of the screen, opening the next page, labeled "SAIL" in which the raft moves from the left to right of the screen, and off the screen.

             

            The page that the raft is on is called PondPage - a MovieClip - and the raft's movement is also a MovieClip. So, essentially, what I'm trying to accomplish, is:

             

            How to make a button be "removed" on command;

            How to play a MovieClip within a MovieClip; and

            How to transition between MovieClip [pages] autonomously after clicking a button that executes the animation in which the Clips change.

             

             

             

             

            Thank you for all of your help.

            • 3. Re: CS5 AS3 MovieClip errors.
              Ned Murphy Adobe Community Professional & MVP

              For that error the following line in your code catches my attention...

               

              flash.display.MovieClip.raft(event:MouseEvent, playAnimation);

               

              What are you trying to do there?  As far as I can tell from what you've described, raft is an object, not a function.

              • 4. Re: CS5 AS3 MovieClip errors.
                Randall_Lanier Level 1

                Well, that particular line of code, I'm not sure how to get it to work. So I was just trying something.

                What I'm trying to accomplish is: when you click a button that says "RAFT" on it, a raft descends from the top of the screen to a certain point, the "RAFT" button is removed, and a new button shows up that says "EXPLORE" and when clicked, the raft moves off the right side of the screen, opening the next page, labeled "SAIL" in which the raft moves from the left to right of the screen, and off the screen.

                 

                The page that the raft is on is called PondPage - a MovieClip - and the raft's movement is also a MovieClip.

                So, essentially, what I'm trying to accomplish, is:

                 

                How to make a button be "removed" on command;

                How to play a MovieClip within a MovieClip; and

                How to transition between MovieClip [pages] autonomously after clicking a button that executes the animation in which the Clips change.

                 

                And I'm not sure how to code it, and I can't find any instructions as to do so, either in books, or online.

                 

                Please help.

                 

                Thank you.

                • 5. Re: CS5 AS3 MovieClip errors.
                  KitClairvoyance

                  I think what you're trying to do on that particular line of code is:

                   

                       addChild(raft);

                       raft.gotoAndPlay(1);

                   

                  To remove a button, I find that instead of removing/readding it as a child, setting the button's visible property to false works for most uses. (: ..it's less complicated than removing it as a child, and then re-adding it when you want it back again.

                   

                  As for your third query, I'm not exactly sure what you mean. You could create a tween object to handle your transitions for you, and hide the old page when the tween is done.

                  • 6. Re: CS5 AS3 MovieClip errors.
                    Ned Murphy Adobe Community Professional & MVP

                    To play a movieclip within a movieclip you target the movieclip from the timeline you are in using dot notation, such as you possibly did when you assigned event listeners to your buttons.  You may have targeted the raftButton properly when you assigned its event listener...

                     

                    pondPage.raftButton.addEventListener(MouseEvent.CLICK,playAnimation);

                     

                    but if you did, then you did not target it properly when you tried to remove it...

                     

                    removeChild(raftButton);

                    that should have been

                     

                    removeChild(pondPage.raftButton);

                     

                    (but that is only if the targeting was correct for the listener)

                    • 7. Re: CS5 AS3 MovieClip errors.
                      Randall_Lanier Level 1

                      Thank you, both of you. I will try it today, and see if I get anywhere. If I don't, you'll see me right back here. Thanks again.

                      • 8. Re: CS5 AS3 MovieClip errors.
                        Randall_Lanier Level 1

                        It didn't work. Here is my code now:

                         

                          
                        //add event listeners
                        startPage.hillButton.addEventListener(MouseEvent.CLICK,onHillButtonClick);
                        startPage.pondButton.addEventListener(MouseEvent.CLICK,onPondButtonClick);
                        hillPage.hillBack1.addEventListener(MouseEvent.CLICK,onBackButtonHillClick);
                        pondPage.pondBack1.addEventListener(MouseEvent.CLICK,onBackButtonPondClick);
                        pondPage.raftButton.addEventListener(MouseEvent.CLICK,onRaftButtonClick);
                        pondPage.exploreButtonRight.addEventListener(MouseEvent.CLICK,onExploreButtonRightClick);
                        pondPage.raftButton.addEventListener(MouseEvent.CLICK,playAnimation);

                        //add event handlers
                        function onHillButtonClick(event:MouseEvent):void
                          {
                           addChild(hillPage);
                           removeChild(startPage);
                          }
                        function onPondButtonClick(event:MouseEvent):void
                          {
                           addChild(pondPage);
                           removeChild(startPage);
                          }
                        function onBackButtonHillClick(event:MouseEvent):void
                          {
                           addChild(startPage);
                           removeChild(hillPage);
                          }
                        function onBackButtonPondClick(event:MouseEvent):void
                          {
                           addChild(startPage);
                           removeChild(pondPage);
                          }
                        function onRaftButtonClick(event:MouseEvent):void
                          {
                           removeChild(pondPage.raftButton);
                               raft.gotoAndPlay(1);
                          }
                        function onExploreButtonRightClick(event:MouseEvent):void
                          {
                           addChild(sailPage);
                           removeChild(pondPage);
                          }
                        }
                        }
                        }

                         

                         

                        I also added a stop(); on the pondPage at the raft layer on frame 1, and on the raft MovieClip as well at the last frame a stop(); so it won't loop.

                         

                        I get this following error: 1120: Access of undefined property playAnimation.

                         

                         

                        Thanks for your help.