Topics
- Final Project Concept Presentations
- Frame-based events
- Timers
- Hit Testing
So far we’ve been working with user-generated Mouse Events. Today we’re going to explore some non-User events that allow us to animate and react with code.
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;
Frame-based Events
Now that we are comfortable with working with and creating display objects, and using event listeners and event handlers, we can also create animation entirely from code, without involving the timeline. To do this, we use a new event type, onEnterFrame, or ENTER_FRAME event.
You might think that you could use a for loop for animation, like this:
for(i = 0; i < 500; i++){ ball.x = i; }
Where “ball” is a display object that you have defined elsewhere. You might think that this code would move the ball 1 pixel 500 times, and in a sense you would be right. The problem is that you would only see the result of the last loop, because all 500 loops are executed before the frame is rendered.
To get around this, you need to introduce time between loops, which is where ENTER_FRAME comes in. The ENTER_FRAME event is dispatched at the frame rate of the .swf.
This is how you set up an enter frame event:
instancename.addEventListener(Event.ENTER_FRAME, eventHandler); function eventHandler(event:Event):void { //do something }
Timer Events
You can also set up an event that will happen at regular intervals in your code. This is called a Timer Event. A timer is actually an object, so first you need to create a new Timer instance, then add an event listener and handler to it, and last, start the timer!
//create the timer instance var myTimer:Timer = new Timer(500, 10); //add the timer event to it myTimer.addEventListener(TimerEvent.TIMER, eventHandler); //start the time myTimer.start(); function eventHandler(event:TimerEvent):void { //do something }
Hit Testing
It can be useful when creating dynamic code based animation to be able to detect when one display object collides with another. This is called “Hit Testing”. You can hit test two ways, with two objects or with an object and a point on the stage.
To hit test two objects, use the hitTestObject method:
object1.hitTestObject(object2)
To hit test and object and a point, use the hitTestPoint method:
object.hitTestPoint(xcoordinate,ycoordinate)
Final Project: Project Planning
The next step in your final project is to create a detailed plan. For next class you need to produce the following:
- Project Brief
- Process Flow
- Storyboards
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.
3. Storyboards
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. You should be able to fully walk us through the functionality of your 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!
FYI, this is how the final project grades will break down:
Final Project Grading:
- 30% Concept and Planning
- 30% Interface and Graphic Design
- 30% Code and Functionality
Hey guys, I won’t be able to join you today. Pneumonia is acting up in my system again, and its best I avoid weather like this for my well being.
Professor, I want to let you know that I want to extend my media player, for my final project, and make it to the top 10 vocalist. I will use the same wireframe, just tweak it a little to have more space for pictures and such. As for the codes that will be learned today, hopefully my friend Rose Mary will help be acquire those.
Don’ worry about me, I’m a fast learner. Ill be working at home while you guys work in school. I just hope I haven’t maxed out my absences :/