Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Variables are to properties as functions are to methods. In other words, methods are functions that are connected to objects. Just like accessing properties of an object, accessing an object's methods requires simple dot syntax. Consider this boarder on the Stage. Again, its instance name is boarder_mc. If I test the movie, you'll see that it animates to make him fall down. That's because I removed the stop action in his first frame, so if I double-click the movie clip, you won't see any action on the first frame.
So the animation plays, and then there is a stop action on the last frame, as you can see right here. Just ignore the other code for now. We'll talk about that later. So I go back to scene one, and let's say I wanted him to stop on frame 1. Go to the first key from the actions layer, and open up the Actions panel. Now you may want to access to code hinting, so let's just type 'var boarder,' and datatype him as a MovieClip, and we'll set it equal to boarder_mc. Now remember this means exactly the same thing.
We could just type boarder_mc instead of boarder, but this is just going to give us access to code hintings. So you can do this whatever way you want. So go down a few lines and type 'boarder.' and then start to type stop, and you'll see it highlighted in the Code Hinting window. Double-click that. Flash types the open parenthesis for you. You can close it out and add a semicolon. So instead of just stop, like when you want to stop the main Timeline, you type the objects name, a dot and then stop, and you are sending a command to that object to stop playing.
So when I test the movie now, the boarder won't animate. So let's say I wanted to have the boarder stop. I want it at a later frame. So let's say I want it to stop at frame 30, or something like that. I can use to gotoAndStop command, so boarder.gotoAnd, and then capital S, and Flash will highlight gotoAndStop, and press Return, and Flash tells me which values that I need to pass into the method. The only one I need a pass in is called Frame.
So I can just type in a frame number. So I'll type in 30, close up the parentheses and the test movie, and there is the boarder on the ground. I can also type gotoAndPlay, so I'll just change Stop to Play, capital P, and then let's say frame 2, and then you'll see the boarder animate again. Let's say you wanted the boarder to fall down when you clicked on him. So the first thing we'll do is to make him stop. So right above gotoAndPlay, I'll type boarder.stop. Make sure to close out the parenthesis and add a semicolon, and then we'll go down a few lines and type boarder.addEventListener.
This is actually another method that the boarder has, and the event is going to be MouseEvent.CLICK. As I type MouseEvent, you'll to start to see MouseEvent.CLICK highlighted, so might as well type that and have Flash write the rest of the code for you. And then type a comma and then type clickedBoarder. Go down a few more lines and create the event handler function, so function clickedBoarder, some parentheses, inside of the parentheses, evt:MouseEvent.
After the parentheses, type :void, all lowercase, wrap boarder.gotoAndPlay(2) inside of the curly braces. So now this code will be executed only when you click on the boarder, because we've attached this function to an eventListener. So we'll test the movie, click on the boarder, watch him fall. So using dot syntax, you can access methods of an object and get all the code hinting you need to run methods without errors.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92470 Viewers
82 Video lessons · 104137 Viewers
71 Video lessons · 75603 Viewers
56 Video lessons · 106976 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.