Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now let's talk about modifying a movie clip's properties with ActionScript. If you're following along in the working files, this file is called MovieClip_Properties and it can be found in the chapter 02 folder of the Exercise Files. As I explained in the last movie, if we want to communicate to an object or modify its properties using ActionScript, we need to give it a unique instance name. Now you may be wondering what are properties? Properties are things you can modify in the Properties Inspector. So if I click on this rectangle, I can modify the width.
So if I change it to, let's say I change it to 125, it should get slightly wider. I can modify the height. I can modify the X position. So if I change it from 335 to 345 you'll see it move to the right slightly. And if you click on the Free Transform tool, you can rotate it. And we can change the transparency or the alpha. If you want to do those with ActionScript again, you need have a unique instance name for that object. So I'm just going to press Cmd or Ctrl+Z on my keyboard, and let's give each one of these objects an instance name. So I'm going to press V on my keyboard to switch to the Selection tool, or you can just click on it in the toolbar and on the left we have rectangle_mc. I'm just going to call this rectangle1_mc.
And let's call the second one rectangle2_mc, and then the one on the bottom right will be rectangle3_mc. Alright now let's create a new layer. I'm going to click on the Insert Layer button in the Timeline and let's name this new layer actions. Now you don't have to name it actions, but that's just to something I do and a lot other people do if they put actions inside their timeline, is give it a special layer, put it at the top and name it actions. The reason why it's at the top is when your swf file loads by default, it loads from the bottom up, so your actions run after everything is loaded. Next step is to lock the actions layer. We don't want to put any art in the actions layer. So I'm going to click the dot under the lock symbol in the actions layer and that'll make it so I can't draw anything on that layer.
Then I'm going to click the blank keyframe in frame one and I'm going to open the Actions panel by going to Window, Actions or pressing Option+F9 on the keyboard if you're on a Mac or on a PC it's just F9. Now you should see all these toolbars on the left and some stuff on the right. You might see the window looking like this with a bunch of extra gray area, because Script Assist is on. First thing I want to do is turn off Script Assist. So I'll go to the bottom right and I'll click the Script Assist button and you know that it's on because it should have little rectangle around it if it's on.
If it's off then you won't have any of that extra gray space at the top of the Actions panel. The next thing I want to do is get rid of the toolbars on the left side of my screen. To do that, I'm going to find that little arrow, it's kind of the divider between the toolbar or tools and the coding area So if I click once on that, it'll go way and now I'm free to type my code in here. The way that I refer to my object in ActionScript is by calling it by its instance name, not the name that I put in the library, the instance name. So I'm going to type rectangle1_mc.
So that's the instance name. This naming convention is very important. When you give it an underscore mc instance name, and by the way you don't have to give it the _mc instance name, you just have to not put spaces or special characters. But if you give it the name _mc, Flash will recognize it in ActionScript as a movie clip. So if I type a dot, a dot is what I use after the object name to speak to it. When I type the dot, Flash recognizes that it's a movie clip because it has the name _mc and then I get this thing called code hinting that comes up. And if I type a property that I want to modify, like if I want to modify the transparency of this object, I can type alpha, and that's the same thing as opacity or transparency. And when it's selected, so I can see that it's selected right here, if I just press Enter or Return on my keyboard, Flash will write out the rest that word for me, which is pretty convenient. So let's type a space equals space. So now we're our saying the alpha or transparency is equal to. Here's something really important to know. The alpha or transparencies, if you're coming over from ActionScript 2, the first thing you need to know is it's called alpha, and not _alpha.
The second thing is the property is not from 0 to 100, it's from 0 to 1. So I'm going to type .5 and then I'm going to type a semicolon and that ends the statement, kind of like a period in a sentence. What I'm telling Flash is set the alpha of rectangle1 to 50%, period or end sentence, which is a semicolon in Flash. Now let's minimize the Actions panel by just double-clicking that Actions tab at the top left of the Actions panel, and we'll just verify that rectangle1 is fully opaque, which means it's not transparent at all. So I'm going to press Cmd+Return or Ctrl+Enter on the PC, to test the movie and then notice it's a lot more transparent, it's 50% transparent.
So let's modify that a little bit more. So I'm going to double-click on that Actions tab to come back up. And then if you get this little menu that I have that says Current selection cannot have actions applied to it, it's because I don't have the right thing selected. So if I click at the top of this and just drag it down a little bit, and I just make sure to click on the Actions keyframe, first keyframe of the actions layer, then I get my code back and I can modify it. If I want to make it really transparent, I can give it an alpha of .15. I'm going to move over this panel, verify that it's fully opaque, test the movie with Cmd+Return or Ctrl+Enter, and we see it's almost fully transparent.
So that's how to modify a property with ActionScript. You just type an instance name and a dot and the property name. You set it equal to some value. Now I know what you're thinking right now, you might be thinking okay, how on earth am I supposed to know that the alpha property accepts a value between 0 and 1, so I have to put a decimal point? How would you ever, ever know that? Well Flash as a really cool code tool. If you just select that alpha, see I'm selecting the property name alpha, and then press F1 on your keyboard. That will open up the Help menu, and it will find that particular property and tell you the values. So check this out.
Right here, alpha property accepts a number, that's after this colon, I'm going to explain the colon a little bit later on. And then right here it tells you what it does. I'm going to select it so you can see. It says indicates the alpha transparency value of the object specified. Valid values are 0 (fully transparent) to 1 (fully opaque). The default value is 1. So if you want to modify any property or if you're curious about a property, you can type the property name select it, press F1 to keyboard and Flash will pop right up to it for you. And yes you could, in the Help menu you could totally do a search, if you want to.
Only problem is, it takes a little bit longer to find it that way, and I recommend doing the select and press F1 method So that's how I can communicate to an object using ActionScript.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101192 Viewers
61 Video lessons · 87945 Viewers
71 Video lessons · 71833 Viewers
56 Video lessons · 103682 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.