Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
With the Code Snippets panel, you can also create custom code snippets. We'll take a look at an example in this movie. One of the snippets, in the Code Snippets panel, is for keyboard control of an object. So you can use that in something like a game, to move an object around. However, the functionality is a little bit limited. I added some functionality to the keyboard control. In this movie, we'll look at making that into a custom code snippet. Let's take a look at the code I have in the Actions panel. Here, I have all the code for keyboard control.
At the very bottom, I'm adjusting the x and y position of an object, and the object is instance_name_here. Note that it is red, and that's significant. We'll take a look at that in just a minute. Wherever you want to have the instance name of an object that's going to be manipulated, you need to put instance_ name_here inside of the Actions panel and make sure that it's red. That means you typed it correctly. So once you have your code, select it all, using your computer's keyboard shortcut, and then you can open up the Code Snippets panel.
I like to open it up directly from the Actions panel. To create a custom snippet, all you have to do is go to the Options area of the panel, toward the top-right, and then choose Create New Code Snippet. Here, you can choose a Title and a tooltip and choose whether to use code selected in the Actions panel. I'll click Auto-fill to do that. For the Title, I'll call this Advanced Keyboard Control, and then I'll type for the tooltip, 'Control an object with the keyboard.
Change speed variable to update speed.' And then I'm going to choose the check box that says Automatically replace instance_name_here when applying code snippet. So I'll check that box and then click OK. In the Code Snippets panel, you'll see there's a new folder called Custom, and if you expand it, you'll see Advanced Keyboard Control. To apply it, I'm first going to delete the Actions layer, and then I'll double-click Advanced Keyboard Control. Since I didn't have the object selected on the stage, I'm informed that this action requires an object to be selected.
So I'll select the instance on the stage. Note that its instance name is biker, and then I'm going to double-click Advanced Keyboard Control. Code is then added to the Actions panel, and if I scroll all the way to the bottom, the instance name is inserted in there instead of instance_name_here. So my code is ready to go. All I had to do is select an object on the stage and then double-click. So I'll test the movie, and using my keyboard, I'll move the biker on the stage. So when you're working with the Code Snippets panel, you can add new snippets by writing the code out, selecting it, and then choosing Create New Code Snippet from the Options area of the Code Snippets panel.
All of this data is actually saved in an XML file, which you can edit if you choose Edit Code Snippets XML. If you ever want to reset to default, you can choose Reset to Default XML to delete your custom snippets. You can also import, as well as export, code snippets. So with the Code Snippets panel, you can create customized code snippets, and you can easily reapply them to objects on the stage.
Get unlimited access to all courses for just $25/month.Become a member
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.