This content has been marked as final. Show 4 replies
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.
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.
So I would recommend looking for a new tutorial that has stuff that looks like this:
// do some stuff
And that the code goes on the frames. :)
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
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:
// 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.