Week 11: Actionscript

We’ll take our first look at Actionscript today and talk about our final projects.

Download these files. We will use them for today’s lesson.

Download this simplified control mc.

Actionscript

What is it? Actionscript is an object-oriented language specifically designed for web animation. It is an event-based language which means that actions are triggered by particular events. Actionscript 3.0 was modeled on the same standards as Javascript so that it would be more familiar to web designers.

Actionscript can go in many places in your movie. However, it is BEST to keep actions on their own layer in the timeline. This makes it easy to see all of your actions in the same place. This is what your timeline looks like when your actions are in the right place:

actions

To get back to your actions, click on the “Actions-Frame” Tab on the top.

Object-Oriented Programming

As mentioned before, Actionscript is an object-oriented language (click on the link to learn more). so it is based on classes of objects. Each class of objects (nouns) has its own propertes (adjectives) and methods (verbs). Let’s say I have a class of objects called horse. Our horse class has properties: height, width and color. It has methods: run, trot, gallop. If we want to tell our horse, which is named “Abracadabra” to trot, we would write it like this:

Abracadabra.trot();

The () are for parameters. Depending on the method, there are different parameters. In this case, there might be the parameters slow and fast.

Abracadabra.trot(”slow”);

Let’s say we want to get Abracadabra’s height and store it into a variable called Abracadabra_height. We would do it this way:

var Abracadabra_height:Number=Abracadabra.height;

Variables:

A variable is a placeholder for information or data. It can hold a String(ie “Name”), Boolean (true or false), an int (integer or whole number), or a Number (any kind of number), among other things. To declare a variable, use the keyword var and state what kind of variable it is after the colon like above. Refer to the file variables.fla in the download for today. Open it up and change the variables to describe yourself. Play around with the if-then-else statement.

Now, the horse class does not actually exist in Flash. Let’s translate this into a class that does exist, like the MovieClip class.

To tell a movieclip with the name “star” to stop, we would write:

star_mc.stop();

To make it play:

star_mc:play();

To store its height in a variable:

var myStarHeight:Number = star_mc.height;

Properties:

Think of properties as your adjectives. They describe your objects. Refer to the file mc_properties.fla in the download for today for examples of moviclip properties.

Moving around in the main timeline:

Let’s backtrack a little bit to the main timeline. How can we get the main timeline to skip around to different frames? We can use the same methods, but like this:

play();
stop();

Notice we don’t need the “star.” in front. Since the actions are on the main timeline, it understands that it affects the main timeline. We could also write it as:

this.play();
this.stop();

“this” is a reserved word in flash, which roughly means, “whatever I was talking about before, that’s what I’m talking about now.”

You can also be more specific about where the timeline plays or stops with these two methods:

gotoAndPlay(10);
gotoAndStop(10);

Refer to the file timeline_methods.fla for more examples.

Events:

In the example control_mc.fla in the download for today, we explore the mouse events “CLICK” and “MOUSE_OVER.”

Here is the whole list of events:
CLICK, DOUBLE_CLICK, MOUSE_OVER (hover), MOUSE_DOWN (click is depressed), MOUSE_LEAVE (mouse leaves stage), MOUSE_OUT (mouse leaves area of object), MOUSE_MOVE (mouse moves), MOUSE_UP (mouse comes up from being depressed), MOUSE_WHEEL (mouse wheel moves).

Functions:

Functions are sets of commands that can be stored for later. In the example, we make a named function like this:

function myFunction(parameters){
//what happens when function gets called.
}

and then call on the function later like this:

myFunction();

Name the instance of your symbol!

Anytime you are controlling a symbol on the stage with actionscript, you need to name that instance. You can do so by clicking on the symbol, opening the properties panel, and then adding a name. Buttons should be named with the suffix _btn and movieclips with the suffix _mc. This will help you program them by triggering the code hints.

Assignment

  1. Begin prototyping your flash site by either creating a paper prototype or a storyboard or both.
  2. Create a movieclip that stops on the first frame until you press a button. Use this as your template, but change the movieclip and the button to suit you.

Leave a Reply

Week 14: Work it!

Almost there! YOU CAN DO IT. I believe in you!!!!

To help you out on your final flash adventures, here are the examples for the day:
Random Animation
Here are some new flash examples.
Sound with Pause
Input Text

Video

The best way to add video for right now is to import the video through the File>Import> Import to Stage menu into an FLV player (top option in the window that opens). You can then convert this video to a moviclip and target as you would other movieclips.

Preloader

Take a look at the example. Basically, I’ve set it up so that it stops on the first frame and keeps checking to see if the whole movie has been loaded (# of bytes). If it has, it plays. Otherwise, it changes the text and the size of the bar. Make sure to simulate download when checking the preloader.

Loader

This is for loading other swf files and jpgs. It’s really handy because then you can build parts separately and add them as needed. It saves on download time, and is great when working in teams.

Sound: Play and Pause

Here, we add some code to our previous simple_sound file in order to keep track of where the song was when we pause it, and then play it in that spot again.

For next week:

We will start at the beginning of class, so have everything ready to go. Test it out, practice a simple presentation of the project, and think of it as an opportunity to practice presenting yourself to an audience. Good luck! I’m looking forward to seeing everyone’s hard work.

Week 13: The Home Stretch!

OMGOMGOMG! Only 2 more classes before the final! Let’s use our time wisely. I’ll run through examples that might be helpful for your final. You ask me questions. Let’s go!

Details »

Week 12: Frame Control, Variables

Check back over the blog post for Week 11, and review the files in the link. To start you thinking about other things that you can do with Actionscript, download this file, and run the examples. See if you can understand how they are programmed.
Details »

Week 11: Actionscript

We’ll take our first look at Actionscript today and talk about our final projects.
Details »

Week 10: Flash

Let’s continue Flash today with Tweens!
Details »

Week 9: Flash!

Flash was always my first love. It combines time-based image editing format with programming and multimedia capabilities! It is a great way to add fluid animation and interaction to your design, and it frees you from the grid constraints of xhtml/css.

Details »

Week 8: Javascript & JQuery

Welcome back! Hope you a restful break and enjoyed the lovely weather. Let’s jump back into things with look at the basic structure of Javascript and JQuery!
Details »

Week 7: Portfolio Presentation and Javascript

Today, you’ll present your portfolio websites and we’ll learn a little Javascript.
Details »

Weeks 5 & 6: Portfolio Lab

We’ll continue working with HTML and CSS today, exploring tables, menus, and images. You’ll begin turning your portfolio designs into live websites!

Details »

Weeks 4: Advanced CSS/Images

Today, we’ll review CSS positioning and explore some tricks with images. We’ll also learn how to use tables and make sitemaps.

Details »