Final Project Requirements

Class, please follow these guidelines when turning in your final projects:

1. Put your .fla and .swf files in my dropbox on the adga server

2. Post your .swf and .html files on your public website, and post a link to the files as a comment on the class blog. If you are unsure how to do this please see me.

You must both turn in your files to me in class and post them online to get full credit.

Posted in Lessons | 11 Comments

LAST CHANCE OFFICE HOURS TOMORROW!!

Class,

I will be in Room 1102 tomorrow, Thursday, May 16th, from 8am – 1:00pm. If you need help with your final project, please come! First come, first served, so come early to make sure you get time with me.

Also, most of the computers in 1102 have CS 5 instead of 5.5, so if you have been using 5.5, remember to save your files down.

Posted in Lessons | Leave a comment

Week 12: Advanced Audio, Video

Advanced Audio

There are a number of different ways you can play audio through Flash, each has it’s advantages and disadvantages.

 PLAYING AUDIO FROM THE LIBRARY

In order to play an audio file from the library, you have to give it a class name. Control or right click on the file name in the library and open the file properties. On the sound properties panel, click the “Advanced” Button in the bottom right of the panel. In the section that opens up, click the “Export for Actionscript” and “Export in Frame 1″ boxes, and give the file a class name. The name of the audio file will automatically get filled in, but you should change this, having the extension in the name will cause problems.

Now you must create a new instance of this sound in your code, using the class name that you set above:

var track:myTrack = new myTrack();

This won’t automatically start the sound playing, however, you have to tell it to play:

track.play();

If you want to stop the sound, things become a little more complicated, as the stop method is actually part of a different object – the SoundChannel class. So you’ll need an instance of this, and you will need to assign that channel to the playback of your file:

var channel:SoundChannel = new SoundChannel( );
channel = track.play();
channel.stop();

This still isn’t the most ideal way to play audio, however, because the audio file becomes part of the .swf and adds to the file size and download time. Any audio file that is more than a few seconds, you should load into the .swf much in the same way that we did with images.

LOADING EXTERNAL AUDIO FILES

This works similarly to the library example, except that we load the sound into a blank generic sound object, using the URLRequest object to hold the value of the audio file name:

var track:Sound = new Sound();
var request:URLRequest = new URLRequest(filename.mp3);
track.load(req);

Adding Video To Your Project

Flash has several options for adding video to your project.

SUPPORTED FORMATS

Flash supports it’s own FLV Video formats as well as Quicktime movies that are H264 encoded. There is a list of supported codes here.

There is also a good article about using H264 video here

USING ADOBE MEDIA ENCODER

You can also convert just about any video format to FLV using Adobe Media Encoder, which is included with Flash Professional. Generally speaking, using FLV in your Flash applications is going to be a smaller file, and better looking and functioning experiences for the user.

However, in order to play an FLV video, you need to create a .swf to act as a player. There are two ways you can play video through a .swf, either by importing it to the Timeline / Library, or using a video component or ActionScript to load in an external file.

IMPORTING VIDEO TO THE TIMELINE OR LIBRARY

I can’t stress enough that you should only use very short video that has no audio track with this method. Video will significantly increase the size of your .swf and load times and this method has serious audio sync issues.

Under the File > Import menu is an Import Video option. When you choose this, you will see the following dialog:

To use video directly in the timeline, choose the “Embed FLV in SWF and play in timeline” option. Note the warning! Also note that you can launch Adobe Media Encoder right from here.

Next choose the embedding method. You can choose to place the embedded video directly on a layer of the timeline, or as a movieclip or graphic symbol.

 

USING VIDEO COMPONENTS TO LOAD VIDEO REMOTELY

Loading video from an external file is a much preferred method, and Flash makes it easy. Choose the “Load external video file with playback component” option from the Import Video panel instead, or you can also drag a FLVPlayback component from the Components (Window > Components) panel directly to the stage:

Under the Video Folder you’ll see several playback component options, as well as the individual elements of the playback component. Drag the component to the stage to add it to the Timeline and your Library.

You can set the appearance and source video of the playback component in the Properties Panel:

OTHER OPTIONS

Because the FLV video must be embedded in a swf player, it has the same platform limitations as any application that uses the Flash Player (ie – no iOS devices). So, if all you need is video playback within a Web site, consider these options:

  • Host the videos on a site like YouTube, Vimeo, or blip.tv and copy and paste their embed code into your html
  • Use a third-party player like JWplayer that detects the users operating system and browser and delivers the appropriate player for that configuration (note, this requires having video in multiple formats)

HOMEWORK

Next week your designs are due, and we will have an all-class work session.

Posted in Uncategorized | Leave a comment

Week 11: Dynamic Text

Announcement:

I will be moving my office hours to Thursday for the remainder of the semester. I will be available in room 1102, Thursday 11:30 – 12:30. Please take advantage of this time as we near the end of the semester!

Topics:

  • Project Brief and Process Flow Review
  • Using Dynamic Text Fields
    • Classic Text
    • TLF Text
    • Embedding Fonts
    • Reading and Writing to Text Field Contents with ActionScript
    • Using Keyboard and Focus Events

Using Dynamic Text Fields

There are methods for dynamically manipulating the properties of text fields with code, but this requires understanding the different types of text in Flash. I’m going to tell you about both types today, but I recommend that you use Classic Text as the TLF engine remains buggy.

Classic Text vs TLF Text

Pre-CS5, there was only one kind of text framework in Flash, what is now referred to as “Classic Text”. If you are using a CS4, this is the kind of text you will be using. If you are making an AS2 application, you will also use Classic Text. Other than that, you will probably want to stick to TLF text, although remember that you will be limited to OpenType and TrueType fonts.

Classic Text Types

  • Static: Non-editable or selectable by user, not readable or writable by actionscript
  • Dynamic: Selectable by user, readable and writable by actionscript
  • Input: Selectable and editable by user, readable and writable by actionscript

TLF Text Types

  • Read only: Same as Static
  • Selectable: Same as Dynamic
  • Editable: Same as Input

Font Embedding

When you are working with dynamic text of any kind, and using anything besides standard Web fonts, you need to “embed” the font in your Flash file. Otherwise, if the viewer doesn’t have that font installed, they will see a system default font. To embed a font, select the text field and click the embed button in the Character section of the properties panel.

In the Font Embedding panel that pops up, you name give the font a name and choose which characters to embed with your file. When you embed a font, it increases the file size of your swf, so you should only embed the characters you need. I usually choose Basic Latin to cover the bases but not load more characters than I need.

Reading and Writing to Text Field Contents with Code

All dynamic text fields have a property called “text” that holds the, well, text.

To access the current text in a text field:

myTextField.text;

To set the text of the text field:

myTextField.text = "some other text";

Make sure you put the text in double quotes!

Keyboard Events

>> Capturing Keyboard Input

You can respond to a user pressing and releasing key on the keyboard just as you can with mouse events. These are called keyboard events. There are two events you can listen for KEY_DOWN and KEY_UP:

//Keyboard Event Listens
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

These events include the information about what key was pressed. This comes in two forms, the keyCode and the charCode. Each of these are numbers that are mapped to characters, but they are a little bit different from each other – a key code value represents a particular key on the keyboard (the 1 on a keypad is different than the 1 in the top row, but the key that generates “1” and the key that generates “!” are the same key) and the character value represents a particular character (the R and r characters are different). Which one you will use will depend on what you are using it for.

function onKeyDown(evt:KeyboardEvent):void {
  trace("onKeyDown: " + evt.keyCode);
  trace("ctrlKey: " + evt.ctrlKey);
  trace("keyLocation: " + evt.keyLocation);
  trace("shiftKey: " + evt.shiftKey);
  trace("altKey: " + evt.altKey);
}
function onKeyUp(evt:KeyboardEvent):void {
            trace("keyUpHandler: " + evt.keyCode);
}

Now, this doesn’t do you much good if you don’t know what numbers correspond to what keys, there’s a list on this page.

Focus Events

A focus event happens when an a user switches between one object and another … like clicking in a text field. You set these up just like any other event, with a listener and a handler.

Homework

Using what you learned about text fields today, make a “MadLib” where a user types in words on one screen, and then reads the Madlib on the next. It should function something like this, although you don’t need as many words to input (10 should do it) and you don’t need the “send” functionality.

Final Project: Storyboards/Interface Designs – Due in Two Weeks

Take your process flow and turn everything that is represented there into a fully designed interface for each step represented there. Design these in whatever tool you are most comfortable with (Photoshop, Illustrator, Flash itself, a combination) but turn the storyboards into a single PDF that you will present to the class in two weeks. You should be able to fully walk us through the functionality of your Flash application with these storyboards. They should represent the near final design of your application. The more time you put into this step, the more time you will have for animation and coding. You are going to need it!

Posted in Lessons | Leave a comment

Week 10: Advanced Events

Topics:

  • Advanced Events
    • Timers
    • Enter Frame
    • Drag and Drop
  • Final Project Requirements
  • Planning Your Project

Advanced Events

Enter Frame

The enter frame event is triggered every time that the movie enters a frame:

//create the enter frame event
addEventListener(Event.ENTER_FRAME,onEnterFrame;

function onEnterFrame(evt:Event) {
//do something
}

This comes in handy when you want to use code to move an object across the stage!

Timers

You can also trigger an event based on an interval of time passing, with a Timer event:

//create the new timer and set the delay and the number of repetitions
var myTimer:Timer = new Timer(1000, 5);

//add the event listeners to handle the timer events when it is detected
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

//start the timer
myTimer.start();

//run this function when the TIMER event fires
function onTimer(evt:TimerEvent) {
//do something
trace("Ding!");
}

//run this function when the timer COMPLETE event fires
function onTimerComplete(evt:TimerEvent) {
//do something
trace("All done");
}

Drag and Drop Events

Any named movieclip instance on the stage can be made “draggable” with the startDrag( ) method.

myObject.startDrag();

Usually this is triggered with an event listener on the MOUSE_DOWN event on the instance. Once startDrag is called, the object will follow the mouse movement. To stop this behavior, you use the stopDrag( ) method, usually implemented on MOUSE_UP.

myObject.stopDrag();

This behavior also has a property associated called dropTarget. The dropTarget is the object that is under the draggable object when the stopDrag method is called. To get the name of the drop target, you must access its name property.

myObject.dropTarget.name;

Final Project

Your final project will take the form of an “Interactive Documentary.” The choice of topic is yours, I suggest something that you are already an expert in or passionate fan of. Your documentary can be instructional (like a ‘how-to’) or informational.

Final Project Requirements

Depending on the focus and execution of your project, it may include more or less of the following components, but must include some of all:

  • Timeline animation
  • Code control of timeline playback
  • Buttons that respond to mouse input
  • Dynamic Text fields and Input Text Fields (we’ll learn these next week)

Optionally, you can also incorporate the following:

  • Audio (we’re going to learn more audio methods next week)
  • Drag and Drop Events
  • Animating with Code (Enter Frame Events)
  • Timer Events

Planning your project

For next week you are going to produce two documents that will help you define your project.

1. Project Brief – This is a text description of your project. It should include the following:

  • Overview: A few sentence summary of the project.
  • Audience: Who is application for? Include age range, gender, anticipated technical skills, language capability.
  • Platform: How do you envision this application being used? Is it part of a larger Web site? A mobile application? Part of an installation?
  • Functionality requirements: Describe how the application will operate. How many distinct states or screens or pages will it have? How will a user interact with it?
  • Technical requirements: Describe as best you can what code elements will be required for the application.

 2. Process Flow – This is a bit like a site map for a Web site. A process flow visualizes the way a user would move through the application from a high level.

Every distinct state or page of the application should be represented by a rectangle, connected by diamond shaped decision points.

Posted in Lessons | Leave a comment

Week 9: AS3 Part 2 – Loading External Assets

Topics:

  • Variables Explained
  • Loading External Assets

Variables

A variable in a programming language is a way to store a value that may or may not be known at the time the program runs, and may change over the life of the application. You can store all kinds of values in a variable – numbers, text, true/false values, the names of objects on your stage or objects you create with code. You can also pass variables as function parameters.

A simple variable declaration looks like this:

var variablename:Type;

Loading External Assets

As you could see from the banner ad exercise, file size adds up quickly when you are bringing graphics into your library. Even if you don’t have the kind of size restrictions that the banners do, an overly large file is going to take forever to download and start playing in the viewer’s browser. One way to minimize this is to load the assets as you need them when the Flash movie is playing. This is similar to the way you include images in a Web page. It also means that you have to upload those images to your Web server along with your swf and html files in order for them to load and display.

Step 1: Create the Loader

You can load images (jpeg, png, or gif only) or other swf files. First you need to create a container to hold the image you are going to load. This container is a special object called a Loader. This is how you create a loader:

var myLoader:Loader = new Loader();

In this example, “myLoader” is a variable Name that you decide, everything else is set.

Step 2: Add the Loader to the Stage

When we create an object like this with ActionScript 3, it doesn’t automatically add that object to the stage. Adding the loader is simple:

addChild(myLoader);

Even though the loader is now part of the stage, you won’t see it. Loaders have no appearance of their own, they are just an empty container to put things into.

Step 3: Identify the asset to load

Next we need to create an object to hold the path to the image or swf that we want to load into the loader. This object is called a URLRequest.

URL stands for “Uniform Resource Location”, which is just a fancy way of saying Web address. In other words, URLs are what you see in the address field of a Web browser. The URLRequest is going to show the path to the asset on our local machine or the server.

There are two ways to represent this path, relative or absolute.

In an absolute path, you give the full address on the local machine or Web server: http://www.domainname.com/subdirectory/filename.ext

In a relative path, you only give need to give the path relative to the swf file the image will be loaded into: subdirectory/filename.ext

It’s best to use the “relative” path to the asset, because this will be the same when you are working on your local machine as when you publish to the Web server. To simplify things and stay organized, keep your assets in a subdirectory (folder) in the same directory (folder) as your Flash files.

So, if you had an image called “my_image.jpg” in a subdirectory called “images” the relative path to it would be “images/my_image.jpg”

You create the URLRequest like this:

var myImage:URLRequest = new URLRequest(imagePath);

In this example “myImage” and “imagePath” are variables. You can either put the image path directly in to the parentheses after URLRequest or create another variable to hold it.

Step 4: Loading the Asset into the Loader

Now that you’ve created the empty container, and identified the asset to go into it, it only remains to load one into the other:

myLoader.load(image);

If you test your movie, you will now see it on the stage. Here’s a couple things to note about the loader object:

Positioning Loaded Content

The loader is placed at the 0,0 coordinates on the stage, so you may want to reposition it. You can do this by accessing it’s x and y properties:

myLoader.x = xposition;
myLoader.y=yposition;

Scaling Loaded Content

The image is loaded into the the loader at 100%. You can scale with code with the scaleX and scaleY properties, but like importing into the library, it’s better to resize it outside of Flash. The larger the asset is, the longer it will take to load, and you don’t want to make the viewer wait around unecessarily. The scale property is a percentage expressed as a decimal between 0-1, so .5 represents 50%. You can scale above 100%, but you’d be blowing a bitmap up larger than its pixel dimensions, which is never recommended!

myLoader.scaleX = myLoader.scaleY = position;

Publishing Your Flash Projects to the Web

Publish Settings

The publish settings panel has three tabs: Format, Flash, and HTML. Before publishing your final movie, you’ll need each of these appropriately.

Modifying the HTML file

You can edit the HTML file that your Flash is embedded into if you are familiar with HTML and CSS.

Embedding Flash in any Web Page

To embed your Flash movie in another Web page, copy and paste everything in between the <div id=”flashContent”> tags:

<div id="flashContent">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="728" height="90" id="FoodFight_728x90_1_v6_as2" align="middle">
                <param name="movie" value="FoodFight_728x90_1_v6_as2.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#cc3300" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="FoodFight_728x90_1_v6_as2.swf" width="728" height="90">
                    <param name="movie" value="FoodFight_728x90_1_v6_as2.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#cc3300" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="window" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="true" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="" />
                    <param name="allowScriptAccess" value="sameDomain" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>

Note: This may look different depending on your version of Flash.

Posting Your Files to the Web

To publish your Flash to the Web, use FTP to move all your files to the Web server. Make sure to upload both your .swf and .html files, and the image files that go with them! If you do not currently have Web space, Citytech students can get a hosting account with Kionic for a reduced price:

http://kionic.com/cuny

Homework

Create a Simple Image Gallery

Using what you have learned today about loading external images, plus the timeline navigation we learned last week, create a simple image gallery using your own images that loads one image at a time onto the stage, and allows you to navigate back and forth through a series of images, as well as jump to the beginning and end, just as you did with last week’s exercise.

Publish your files to your web space. Remember that you must upload your image files as well as your html and .swf files. Also bring your .fla files to class next week so I can look at them if I need to.

Post a link to your HTML file as a comment on the blog.

Final Project

After Spring Break we are going to start work on your final projects. Your final project is going to be an interactive “documentary” project. The subject of this documentary is up to you. I encourage you to pick something you already have some knowledge about, and some passion for. The project can be instructional like a “how-to” or more informational. You don’t have to do anything for the final project yet, but start thinking about it.

Posted in Lessons | 2 Comments

Midterm Grades

Class:

Check your attendance and assignment grades here –

https://docs.google.com/spreadsheet/ccc?key=0AiWa4hnw5mx7dHVNQ0dKOURmclFpamxwSG5ySC1jaFE

Anything that is listed as a 0 (zero) on this sheet means that I did not receive this assignment from you.

If you are missing any homework, please get it to me no later than 12 noon THIS THURSDAY – 3/29. There are three ways you can get the work to me:

  1. You can email a .zip file to me at classes@catherinegarnier.com as long as it is no larger than 10MB.
  2. You can  use Dropbox or some other file sharing service, but please use the above email address to notify me.
  3. You can drop the files off to me in Room 1102 on Thursday at 11:20 when my class there ends. If you are going to do this, please let me know ahead of time, I’m not going to hang out there waiting to see if anyone shows up

After Thursday I will turn in the Midterm grades, and you will not be able to turn in any of the previous assignments in for credit.

Please email me immediately if you have any questions.

Posted in Uncategorized | Leave a comment

Week 8: Introducing Interactivity

  • ActionScript Basics
    • Using the Actions Panel
    • Flash Banner Ads with ActionScript 2:
      • Creating an invisible “button”
      • Adding Behavior to an object on the stage
      • Using the Trace function to test your code
    • ActionScript 3
      • How to Set up your Files for AS3 applications
      • Targeting an object in AS3
      • Creating Custom Functions
      • Creating an Interactive Button in AS3
      • Using ActionScript for Timeline Control

ActionScript Basics

ActionScript is the language used to program interactivity in Flash. It is what is called an Object Oriented Language, or OOP. We’ll talk more about what that means as we go along. ActionScript is also client-side language, which means that all the processing takes place on the end users machine. In practical terms, this means that the Flash movie can change without reloading the container HTML page, but it also means that Flash cannot save any information back to the Web server.

There are two ways to include ActionScript with your Flash movie, via the Actions panel, or a separate .as files. In this class we are going to explore the first method.

The Actions Panel

Actionscript is adding to your Flash movie through the Actions panel, which you can open either through the Windows menu or Shift+F9 .

The Actions panel will always show you the code for the object on the stage you currently have selected.

ActionScript Syntax

ActionScript is comprised of a series of statements that are always ended with a semi-colon:

some code here;

A more complex statement might be enclosed in curly brackets:

{
  more complex code;
  some more code;
}

If you want to include notes that won’t be read as code, you can do that in the form of comments. There are two types of comments in Actionscript:

// This is a single line comment
/* This is a multi-line
or block comment */

There are also a few naming rules to keep in mind:

  • Code is case sensitive: MovieClip is not the same thing as movieclip
  • Don’t create names that start with a number (it’s ok to have a number elsewhere in the name)
  • Don’t use non-alphanumeric characters in names except hyphen (-) or underscore ( _ )

Flash Banner Ads with ActionScript 2

ActionScript has gone through three versions, 1.0, 2.0, and 3.0. For the most part you should now exclusively use ActionScript 3.0, however the one exception you may encounter in your professional practice is Flash banner ads. Many sites use a click tracking system called ClickTag which is not compatible with AS 3.0. We’re going to review how to set up a ClickTag for a banner ad with ActionScript 2.0, in the case that you might need to do this in the  future.

Keep in mind that there are a few things you can’t use if you are working in AS2, because they were introduced with AS3:

  • 3D objects and transforms
  • TLF Text (use Classic)
  • Bone tool armatures

Step 1: Creating the Invisible Button Symbol

  1. Create a new layer at the top of your timeline layers
  2. On that layer, draw a rectangle on the stage that is the same size as the stage.
  3. Convert the rectangle to a Button symbol (not a MovieClip or Graphic!)
  4. Give the button symbol on the stage an instance name
  5. Open the button symbol to edit it. Copy the rectangle keyframe to the “Hit” frame. Clear all the other frames, so it looks like this:

This will make the button invisible, but clickable. Yay!

Step 2: Adding Behavior to an Object on the Stage

In AS2 (but not AS3!) you can add Actionscript directly to a MovieClip or Button instance on the stage via the Properties panel, by clicking the little arrow at the top right of the panel:

This will open the Actions panel for that object.

The code for creating an “on click” behavior in AS2 for your button is as follows:

on (release) {
 // put what you want to happen when the button is clicked here
}

Step 3: Using the Trace function to test your code

To test whether you’ve added the button and the behavior correctly, you can use the trace function. The trace function will send data to the output window when you are in Flash, but is invisible to the user once the Flash movie is published as a .swf online.

on (release) {
   trace("click");
}

To add a link to the click behavior, use the getURL function:

on (release) {
   getURL("http://www.google.com", "_blank");
 }

The first parameter is the full path to the web page you want to open. The “_blank” parameter will force the linked URL to open in a new browser window.

If you need to use a ClickTag, you will use this code instead:

on (release) {
 getURL(clickTAG, "_blank");
}

ActionScript 3.0

How to set up your files for AS 3.0 Applications

As I’ve mentioned, you cannot add ActionScript directly to objects in AS3. Instead, you can add code to any frame or sequence of frames on the Timeline. This includes the timelines of symbols.

While you can add code to any layer on the timeline, including layers that have symbols or other objects on them, it is much cleaner to designate a single, empty layer for your code. This will prevent you accidentally erasing code or objects when working with one or the other, and it will also make it easier for you or another developer working on the code to find it later.

With this goal in mind, I want you to place all your ActionScript on a single layer at the very top of your timeline called “actions”. So, the first thing you do now when creating a new file is to make this layer, then open the Actions panel and pin this layer so that it is always easy to get to it.

Targeting Objects on the Stage with ActionScript 3.0

Because you are no longer able to add behavior directly to objects, you need to be able to tell actionscript which object on the stage you are adding behavior to. In order to do this, you must target the object using its instance name. That means that every object on the stage that you want to be interactive must have an instance name!

Then, when you want to refer to that object in your ActionScript, you can call it by name, using object notation:

buttonone.dosomething();

You can also find named objects on the stage using the target button in the Actions panel:

Object Properties and Methods

The core functionality of any object-oriented programming language are classes, objects, properties and methods.

Every object on the stage is an instance of a defined class of object within the ActionScript core library. These classes have properties and methods attached to them, and these vary depending on the class. Here’s an easy way to think of the difference between a property and a method:

  • Properties define what an object is
  • Methods describe what an object does
When working with an instance on the stage, you’ll access the properties of that object like so:

instancename.propertyname;

You can change the value of that property like this:

instancename.propertyname = value;

Methods are called like this:

instancename.methodname(arguments);

Creating Custom Functions

ActionScript 3 has many built in functions, like the trace function which we’ve already used. You can also create your own functions, to hold code that you want to be able to reuse anywhere in your project. First you define the function:

function functionname(parameter1,parameter2):return {
    //do something
}

Then, when you want to use the code in the function, you call it using the function name like this:

functionname (value1,value2);

The values in the parentheses are parameters, extra information you can pass into the function when you call it. For example, when you call the trace function, the parameters are whatever you put between the parentheses that you want to send to the output window.

Creating an Interactive Button in AS 3.0

When creating a button or other interactive object in ActionScript 3, there are two steps you must create: an event listener, and an event handler. You can add event listeners and handlers to Button and MoveClip Instances but not Graphic symbols.

The Event Listener

The event listener describes what object to target, and what event to respond to. You do this using the addEventListener method.

This function takes two parameters, the event to respond to (like a mouse click) and the function to run when the event is detected.

 

The first parameter above describes an event of type MouseEvent, and the CLICK event is the particular event that is being listened for. Here are all the MouseEvents you can listen for:

  • CLICK
  • DOUBLE_CLICK
  • MOUSE_DOWN
  • MOUSE_MOVE
  • MOUSE_OUT
  • MOUSE_OVER
  • MOUSE_UP
  • MOUSE_WHEEL
  • ROLL_OUT
  • ROLL_OVER

The Event Handler

The event handler is a function that you must define, to describe what you want to happen when the event happens.

Using ActionScript for Timeline Control

So far animation that you have created on the timeline plays automatically and continuously. You can use ActionScript to control when your movie starts and stops, and to jump around the timeline.

There are a number of timeline related methods of the MovieClip class that you can use to control playback of your main or MovieClip nested timelines:

  • stop( ) – This will stop the movie wherever it appears on the timeline
  • play( ) – Starts playback of the movie
  • nextFrame( ) – Advances the movie one frame
  • prevFrame( ) – Rewinds the movie one frame
  • gotoAndPlay(frame) – Goes to the specified frame (either by name or number) and start playing from that point.
  • gotoAndStop(frame) – Goes to the specified frame (either by name or number) and stop there

There is also one timeline related property that will help you do your homework:

  • currentFrame;

All the properties and methods of the MovieClip class are detailed here

Homework

Take the original walkcycle exercise or the bone tool exercise (or really any of the animation assignments)  you did earlier in the class, and add buttons that do the following:

  • Play
  • Stop
  • Move Forward 1 Frame
  • Move Back 1 Frame
  • Jump to the End
  • Go Back to the Beginning

Here’s a hint: Anything that’s a number in Flash (like frame numbers) can be used  to do simple math – add, subtract, multiply and divide.

Posted in Lessons | Leave a comment

Week 7: 3D Transformations, Audio Part 1

Topics:

  • Working in 3D
    • 3D Rotation Tool
    • 3D Translation Tool
    • Global vs. Local Transforms
    • 3D in the Properties Panel
    • 3D in Transform Panel
    • 3D Tweens
  • Audio Part 1: Timeline Audio

Working in 3D

So far we’ve been restricting ourselves to the X and Y axes in our Flash animations, but the time has come to venture into the Z! Today we are going to look at the 3D tools, and 3D Motion Tweens. First there are a couple of things you should know about 3D in Flash:

  • The native 3D in flash is really what we like to call “2 1/2 D” because while you can move and rotate object on three axes, the object themselves are still two-dimensional. To get truly 3D object in Flash you will need the help of third party code libraries.
  • 3D transforms only work if your publish settings are set to Actionscript 3.0 and Flash Player 10.
  • 3D transforms increase file size and processing requirements, so only use them when you need them!
  • You can only perform 3D transformations on MovieClips and TLF Text!

3D Rotation Tool

This is the “top” tool in the 3D tools panel. The three axes of rotation are represented by Red (X), Green (Y), and Blue (Z) circles which you can grab and drag independently with your mouse. Click and drag outside of those circles, within the orange bounding circle, and you can rotate organically in all three dimensions.

3D Translation Tool

This is under the 3D rotation tool. This allows you to move your object in 3D space. The three axes are represented by Red (X), Green (Y), and Blue (Z) arrows, and you can move in that dimension by clicking and dragging on the associated arrow. You can only move in one direction at a time

Global vs Local Transforms

By default, the X,Y,Z axes and coordinates are represented relative, or local, to the object, but if you want to see them relative to the global stage coordinates, you can toggle the Global Transform Button at the bottom of the Tools palette or hit ‘D’.

3D in the Properties Panel

If you want more precise control over your 3D positioning, you can manipulate it in the Properties panel for the selected object. You can also change the Perspective Angle and Vanishing Point here, which will affect how your object appears to move forward and back in the Z axis.

3D in Transform Panel

If you want more precise control over your 3D rotation, you can manipulate it in the Transform panel (not the free Transform tool). You can also change the 3D center point, which is where the object will rotate from.

3D Tweens

You can only apply Motion Tweens to objects with 3D properties – Classic Tweens won’t work. When you apply a Motion Tween to an object with 3D properties set, the 3D Tween option in the contextual menu will automatically be checked. 3D tweens work the same as regular motion tweens, just with the addition of the 3D position and view properties — all tweenable!

There is additional information about 3D transforms in Flash here:

Exploring the new 3D features in Flash CS4 Professional

Using Audio Part 1: Timeline Audio

There are a number of different ways you can play audio through Flash, each has it’s advantages and disadvantages.

Supported Audio types

Many audio types are supported in Flash, but you’ll have best luck with .aiff or .mp3 files. All audio is published out of Flash in the mp3 format, so this is a good format to start with.

Import to Library

You add audio to your Flash movie the same way you import other media assets. You can use either “Import to Library” or “Import to Stage” but either way the audio file will end up in your library, but not on the stage.

Select an imported audio file in the library, and you will see a visual representation of the sound file, in addition to tiny little play and stop buttons to the top and right that allow you to preview the audio file.

To see additional properties of the sound file, double-click the speaker icon next to the filename.

Check your file size! This is going to impact the total size of your swf. You can adjust the compression settings here for this file only or in the Publish Settings panel for the whole movie.

Adding Audio to the Timeline

You add audio to a keyframe on the timeline, in the properties panel when you have a frame selected. The audio will start playing when the swf hits that frame.

Choose the sound you want to add with the “Name” pulldown in the sound section of the properties panel.

Once you do this, you will see the waveform of the sound in the timeline.

Increase the height of the layer by control or right clicking the layer name and changing the layer height:

How the file will playback depends on how the Sync property is set. There are two primary settings you should concern yourself with here:

Event – Plays whole audio file. If you don’t want this, you can do some minor editing in the sound properties. This should be reserved for very short sounds, or you will get awkward echoing as the movie loops and continues to play the sound again and again.

Stream – Plays the sound only as long as the timeline. You can set the repeat and loop settings for replay, but this will always stop a previously playing sound before starting the next one.

The problem with both of these methods is that you aren’t giving the user any control over the playback of the sound. I generally avoid timeline sound in favor of one of the methods we will learn later in the class.

Homework

Choose a song with lyrics and import it into Flash. Create a 10-15 second animation of the song lyrics in time to the music using 3D tweens. The bulk of your animation should be text, but you can use other graphic elements if you like. If you are able to edit the audio file outside of Flash, cut it down to the portion of the track you wish to animate.

Posted in Lessons | Leave a comment

Week 6: Advanced Animation Part 1: Bone Tool, Motion Presets

>WEEK 6 EXAMPLES

TOPICS:

  • Motion Presets
    • Using
    • Saving
  • Bone Tool

MOTION PRESETS

Flash ships with a number of these, which are basically canned motion tween animations. Use these sparingly, and always customize them for your project. “Out of the box” they are very recognizable and make you look like an amateur. More interesting is the ability for you to save your own motion presets, handy when you are doing a project where you are going to use the same transitions multiple times.

USING THE BONE TOOL

The Bone tool allows you to create an armature of “bones” using either shapes or symbols to create dynamically linked characters or objects that use something called “inverse kinematics” to animate them. You can use bones on either a series of linked symbols or a shape, to different effect.

The Bone Tool only works with CS4 and above, with Actionscript 3. There are some small differences between CS4, CS5 and CS5.5.

Homework

Create a 10 second animation using the Bone Tool, either using linked symbols or shapes. This can be a character animation, something mechanical, something abstract, it’s your choice, just have fun and be creative!

Posted in Lessons | Leave a comment