Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Modifying MovieClips properties

From: ActionScript 3.0 in Flash CS3 Professional Essential Training

Video: Modifying MovieClips properties

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.

Modifying MovieClips properties

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.

Show transcript

This video is part of

Expand all | Collapse all
  1. 2m 3s
    1. Introduction
      39s
    2. How to use the exercise files
      1m 24s
  2. 3m 53s
    1. Why you should learn ActionScript 3.0
      52s
    2. Differences from ActionScript 2.0
      1m 56s
    3. Moving beyond Script Assist
      1m 5s
  3. 21m 57s
    1. Communicating to MovieClips
      4m 7s
    2. Modifying MovieClips properties
      7m 0s
    3. Understanding variables
      50s
    4. Setting variable data types
      3m 23s
    5. Using trace statements
      2m 39s
    6. Using comments
      3m 58s
  4. 26m 3s
    1. Understanding functions
      1m 23s
    2. Using functions
      2m 27s
    3. Writing custom functions
      4m 25s
    4. Making a function modular
      11m 50s
    5. Making a function return a value
      5m 58s
  5. 41m 45s
    1. Understanding event types
      1m 28s
    2. Using a listener to catch an event
      3m 14s
    3. Writing event handlers
      6m 56s
    4. Responding to mouse events
      4m 33s
    5. Responding to keyboard events
      5m 45s
    6. Creating a link to a website
      5m 26s
    7. Using the enterframe to create animation
      7m 34s
    8. Using the timer event to control animation
      6m 49s
  6. 44m 32s
    1. Understanding classes
      1m 48s
    2. Writing a custom class
      4m 21s
    3. Extending an existing class
      2m 16s
    4. Understanding methods
      2m 11s
    5. Public vs. private properties and methods
      2m 46s
    6. Bringing a class object to the timeline
      14m 16s
    7. Defining a document class
      8m 13s
    8. Setting up a classpath
      6m 20s
    9. Creating useful classes
      2m 21s
  7. 36m 4s
    1. Understanding conditional statements
      1m 36s
    2. Writing a conditional statement
      4m 40s
    3. Understanding conditional operators
      1m 37s
    4. Using conditional operators
      4m 49s
    5. Setting up alternate conditions
      4m 43s
    6. Writing compound conditions
      4m 22s
    7. Understanding loops
      1m 30s
    8. Creating a code loop
      2m 58s
    9. Using a loop to generate instances of a class
      3m 44s
    10. Placing loop-created instances
      6m 5s
  8. 12m 49s
    1. Understanding the math class
      1m 5s
    2. Using basic math operators
      1m 46s
    3. Generating random numbers
      2m 15s
    4. Using different techniques to round numbers
      7m 43s
  9. 56m 20s
    1. Creating a text field
      3m 27s
    2. Styling a text field
      6m 28s
    3. Capturing data from a text field
      7m 38s
    4. Loading external text
      8m 25s
    5. Scrolling a text field
      5m 14s
    6. Understanding arrays
      9m 48s
    7. Using text and arrays to create a game
      8m 24s
    8. Finishing the text game
      6m 56s
  10. 1h 9m
    1. Storyboarding your application effectively
      3m 13s
    2. Writing a memory card class
      5m 57s
    3. Writing a memory game class
      3m 51s
    4. Adding graphics to cards
      9m 20s
    5. Placing cards
      7m 33s
    6. Detecting matches
      8m 40s
    7. Resetting cards
      4m 53s
    8. Handling incorrect matches
      5m 14s
    9. Determining a win
      3m 51s
    10. Adding additional cards
      6m 47s
    11. Randomizing cards
      10m 17s
  11. 36m 30s
    1. Drawing with code
      8m 12s
    2. Creating a color change
      5m 20s
    3. Generating a random color change
      6m 58s
    4. Animating a color change
      4m 50s
    5. Using filters
      3m 30s
    6. Modifying filter properties
      4m 13s
    7. Animating filters
      3m 27s
  12. 51m 50s
    1. Loading external images and Flash movies
      4m 1s
    2. Communicating to loaded movies
      6m 31s
    3. Loading sound
      4m 6s
    4. Starting and stopping sound
      6m 18s
    5. Pausing and resuming sound
      9m 46s
    6. Managing the volume of sound
      5m 41s
    7. Understanding Flash video connections
      1m 0s
    8. Loading video
      5m 33s
    9. Controlling video playback
      8m 54s
  13. 45m 54s
    1. Overview of creating a drag-and-drop game
      57s
    2. Creating drag-and-drop class
      12m 7s
    3. Detecting collisions
      8m 44s
    4. Responding to collisions
      9m 1s
    5. Detecting a win
      4m 2s
    6. Adding drop shadows
      3m 43s
    7. Randomly placing objects
      7m 20s
  14. 23s
    1. Closing
      23s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed ActionScript 3.0 in Flash CS3 Professional Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK

Course retiring soon

ActionScript 3.0 in Flash CS3 Professional Essential Training will be retired from the lynda.com library on October 10, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion.


Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.