4 Replies Latest reply on Nov 15, 2008 12:39 PM by Rothrock

    Conflicting Errors?

    Hobonicus
      I apologize for my lack of knowledge, I'm trying to follow a tutorial to get a better idea of how actionscript works. I'm trying to get an object to move with the arrow keys.

      I originally had the code pasted on frame one of the main timeline and got this error: Clip events are permitted only for movie clip instances. So okay, I guess I have to put it on the movie clip then, and a google search confirms this.

      So I put the code on the movie clip and I get this error: Statement must appear within on/onClipEvent handler. I google this problem and find that I can fix it by putting the code on the main timeline... On this site alone I found three topics that say placing the code on the timeline and removing it from the movie clip will solve the problem, but that doesn't solve the problem for me, as I just get the first error. Thanks for any help, here's the script pasted directly from the tutorial:
        • 1. Re: Conflicting Errors?
          robdillon Most Valuable Participant
          In actionscript 2 you have two available methods for connecting your code to the objects on the stage. One method is to select a movieClip or button object on the stage and then write actionscript. The code that you show above is meant to be attached directly to a movieClip.

          If you select a movieClip object on the stage, and then open the Actions window, you should see the title, Actions - MovieClip at the top of the window. If you select a button object on the stage, you will see Actions - Button at the top. If you see something different, then you haven't selected a movieClip or a button.

          A second method for connecting you code to the objects on the stage, is to give an instance name to each object, then write the actionscript to a frame actions window and reference the object's instance name. This is the preferred method.
          • 2. Re: Conflicting Errors?
            Rothrock Level 5
            The second error is most likely caused by the line numbers. That is the only thing I can see that would cause the second error. Because everything is inside the clipEvent handler except the number "1."

            And Rob Dillon is correct in explaining the differences. But I don't think he goes far enough. The style of coding by placing the code directly onto the movie clip is only a good choice if you are publishing for flash 5. When Flash 6 came out in 2001 they gave a better way of putting the code on the frames.

            In fact if you want to continue learning Actionscript and move forward with it, AS3 has removed the ability to place code directly on the clips. But the biggest drawback to me is that you end up with some code here, some code there and it is really difficult to maintain and update. Here is a really good blog about the difference.

            http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent

            So I would recommend looking for a new tutorial that has stuff that looks like this:

            myClip.onEnterFrame=function(){
            // do some stuff
            }

            And that the code goes on the frames. :)


            • 3. Re: Conflicting Errors?
              Hobonicus Level 1
              Thank you for the help! The second problem was caused by the 1 being outside the clipEvent handler. The code works now without error, although I am not sure how to reference an instance name so I'm not using the code from the timeline, which I've heard numerous times is the preferred method.

              I originally decided to start with AS2 as it seemed much less complicated and there were more tutorials on it. Again, thanks for all the help :D
              • 4. Re: Conflicting Errors?
                Rothrock Level 5
                Glad that worked out for you. In some ways AS2 is less complicated, in others it is more complicated. If you really plan to learn a lot of Actionscript and take this a ways you really will want to stop learning the old "on()" style. There is still a lot of call for AS2, but there will be more and more for AS3 and if you are just coming into it a lot of AS2 notions will mess up your head for AS3.

                In any even it is really easy to give an instance name to a movieclip. When you have a clip on stage make sure that only it is selected and in the properties panel is field for "<instance name>" You put any name you want in there.

                Make sure the name is unique

                Do not start with a number (ending with one is fine)

                Do not use spaces

                Do not use special characters like ?/."&, some will work some will break it is easy to avoid them all. _ and - are fine however.

                I like to intercap my names like, myCurrentClip1 or menuBar, etc.

                Give it a name that is sensible.

                So let's say you have name your clip redTruck. Then in your code you would do this:

                redTruck.onEnterFrame=function(){
                // some stuff
                }

                Very easy. And the benefit is if you also have a blueTruck all your code will be in one frame and not on the different clips.