Away3D Programming Tutorial - Mouse Interaction
Learn how to respond to mouse events in Away3D. Demo and source code included.
VIEW THE DEMO
DOWNLOAD THE CODE
Mouse interactivity is a must for all but the most simple web applications, and 3D flash applications are no exception. Not only does it allow the application to respond to a users requests, but allowing the user to click on and interact with an application also entices the user to investigate your application further. You've probably already seen this user interaction with a lot of Flash advertisements. Thankfully it is quite easy to respond to mouse events with Away3D.
Our ApplicationManager class has 4 properties: mesh, rotation, meshScaleTween and meshRotateTween. The later 3 properties all relate to tweening the mesh on the screen in response to a mouse event. This application makes use of the TweenMax class. Previously I have made use of the Tweener class, which does much the same thing, but TweenMax has some nice features, like yoyo, that made me switch. The mesh property is a standard MeshObject, which you can read about in a previous tutorial here.
In the startupApplicationManager function we create and initialise the MeshObject as per usual, this time with the built in Cube primitive. The mouse interaction comes about from the functions we attach to the mouse events MOUSE_DOWN, MOVE_OUT and MOVE_OVER. If you have ever manually hooked up event listeners for standard GUI code then this should look familiar. If not, these 3 lines of code allow us to watch for when the mouse button is pressed over the cube, when the mouse is moved over the cube, and when the mouse is moved off the cube.
The mouseOver, mouseOut and mouseDown functions hold the code that is executed when these mouse events are triggered. All three setup a new TweenMax animation: the mouseDown function rotates the cube, the mouseOver function sets up a yoyo tween that bounces the scale of the cube from 1 to 2, and the mouseOut function sets up a tween to return the cube back it its original scale.
Responding to mouse events really is that simple: you simply add an event listener and create the corresponding function. If you want to do some more advanced mouse interaction I recoomed you check out the MouseEvent3D class, which is the parameter that is sent to the event listener function. There is a wealth of information in the MouseEvent3D class like mouse coordinates, texture coordinates, the object that was clicked on, the material that was clicked on and more.
Find more Flash tutorials here.

-
Away3D Programming Tutorials - Getting Started
| By mcasperson | in Programming
Learn how to get started with the Away3D Flash 3D engine with this detailed, step by step tutorial. Demo and source...
-
Away3D Programming Tutorial - Effects
| By mcasperson | in Programming
See how you can add the standard Flash filters to any Away3D object to easily create advanced effects. Demo and sou...
-
Away3D Programming Tutorial - Primitives
| By mcasperson | in Programming
See how easy it is to use the build in primitive shapes supplied with Away3D. Demo and source code included....
-
Away3D Programming Tutorial - Environment Material
| By mcasperson | in Programming
See how to use the EnviroBitmapMaterial to create a real time reflective look in Away3D. Demo and source code inclu...
-
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , is integer , check Is Zero , Get Que | By xxris | in Programming
Javascript functions for : trim, right trim, left trim, no Apostrophe, is Empty , is Digit , VarChar To Number , i...
-
How to access and use a Window's command line | By MaxwellPayne | in Programming
Learn about the Window's command line in DOS and how to use it....
-
Zen Cart Development – Improved Open Source for Shopping Cart | By dainawill | in Programming
Main task of every online merchant is not only to launch the online store successfully but to keep it on the same l...
-
How to Learn to Program Your Computer | By dsj8760 | in Programming
This article is about learning to program a computer. It is a general article giving tips on how to learn about pro...
-
Jailbroken iPhones get RickRolled | By explorer | in Programming
First iPhone worm, attacks via SSH and does the classic rick roll gag on the user....
-
Away3D Programming Tutorial - Environment Material | By mcasperson | in Programming
See how to use the EnviroBitmapMaterial to create a real time reflective look in Away3D. Demo and source code inclu...
-
Away3D Programming Tutorial - Primitives | By mcasperson | in Programming
See how easy it is to use the build in primitive shapes supplied with Away3D. Demo and source code included....
-
Away3D Programming Tutorial - Effects | By mcasperson | in Programming
See how you can add the standard Flash filters to any Away3D object to easily create advanced effects. Demo and sou...
-
Away3D Programming Tutorials - Getting Started | By mcasperson | in Programming
Learn how to get started with the Away3D Flash 3D engine with this detailed, step by step tutorial. Demo and source...
-
Papervision 3D Programming Tutorial - Creating a Papervision Component | By mcasperson | in Programming
See how Papervision can be packaged into a SWC Flash component, which allows you to drag and drop Papervision into ...








No comments yet.