Changing Mouse Cursor in Flash AS3


In this tutorial, we are going to learn and implement a custom cursor in our flash movies, using the the Mouse & MouseEvent Classes and their functions in ActionScript 3.0.

In this basic tutorial, you are also going to learn to use the Align Tool to orient objects with pin-point accuracy. So it is recommended you go through this article for the basics of The Align Panel in Flash...

Basic Tweening with ActionScript 3.0

In this tutorial, we are going to learn how to Tween objects on stage using the Tween Class. The Tween Class lets us easily create animations of objects by specifying the property to be tweened and the initial and final values. 
This method is useful to create animations on the fly...  
It is sujjested you read this article on timeline animation and tweening to understand the basics of Timeline aniamtion and Tweening using the timeline before learning to Tween using code.

Manipulating Objects in Flash AS3

This is a basic tutorial that aims at teaching those who are new to Flash, ways to move objects (MovieClips,Buttons etc.) on the Stage and throws light on the various properties of movieclips and buttons and the ways to manipulate them...

Let's start off by creating a new Flash file (Ctrl+N). Now add/create a movie clip onto the stage of the main movie. I have imported this image (Ctrl+R) onto the stage and converted it into a movieclip (F8).
This should be the Object that we will be manipulating with the help of actionscript. Now we need to give this movieclip an instance name so that we can refer to it while writing our code. To do so, fire up the properties window/pane (Ctrl+F3) and set the instance name to "myObj_mc".


Now we will add buttons onto the stage which will control the movement and properties like transparency (alpha). Add 4 buttons to move the Object in the four directions respectively to act as controls to move the movieclip around and add another button to control transparency as show below.

 Now change the instance names of the button with the left arrow to "left_btn", right arrow button to "right_btn", up arrow button to "up_btn", down arrow button to "down_btn" and the button that says transparent to "alpha_btn".
Once we are done with this, we can proceed to the actionscript part. 


Code ::

up_btn.addEventListener(MouseEvent.MOUSE_DOWN,up_fn);
down_btn.addEventListener(MouseEvent.MOUSE_DOWN,down_fn);
left_btn.addEventListener(MouseEvent.MOUSE_DOWN,left_fn);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN,right_fn);

alpha_btn.addEventListener(MouseEvent.MOUSE_DOWN,alpha_fn);

function up_fn(e:MouseEvent)
{    myObj_mc.y-=10;
   
// this  is equivalent to: myObj_mc.y=myObj_mc.y-10; }
   
function down_fn(e:MouseEvent)
{    myObj_mc.y+=10;
    }
   
function left_fn(e:MouseEvent)
{    myObj_mc.x-=10;
    }
   
function right_fn(e:MouseEvent)
{    myObj_mc.x+=10;
    }
   
function alpha_fn(e:MouseEvent)
{    myObj_mc.alpha=0.5;
    }


Code description ::

up_btn.addEventListener(MouseEvent.MOUSE_DOWN,up_fn);
down_btn.addEventListener(MouseEvent.MOUSE_DOWN,down_fn);
left_btn.addEventListener(MouseEvent.MOUSE_DOWN,left_fn);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN,right_fn);


alpha_btn.addEventListener(MouseEvent.MOUSE_DOWN,alpha_fn);


In these first few lines, we are creating eventListeners to detect events from the event stream and when a "MOUSE_DOWN" event is detected, it calls the corresponding functions wherein we define how it should react to such an event.
MOUSE_DOWN is a subset of class MouseEvent and when the event is recorded, it calls the corresponding function with arguments as a MouseEvent...


function up_fn(e:MouseEvent)
{    myObj_mc.y-=10;
   // this  is equivalent to: myObj_mc.y=myObj_mc.y-10; }
   
function down_fn(e:MouseEvent)
{    myObj_mc.y+=10;
    }
   
function left_fn(e:MouseEvent)
{    myObj_mc.x-=10;
   

}
   
function right_fn(e:MouseEvent)
{    myObj_mc.x+=10;
    }
   
function alpha_fn(e:MouseEvent)
{    myObj_mc.alpha=0.5; //sets transparency to half
    }



In the above code, "x" "y" and "alpha" marked in green, are properties of movielips that define the placement along X-axis , along Y-axis and the transparency respectively.
When we say myObj_mc.y-=10; This means that we are moving the movieclip by 10pixels, upwards. Similarly, the movements along other directions are written in the other functions and the transparency is set to half when the corresponding button is pressed (refer alpha_fn function).

Note:: The origin is considered to be at the top-left corner and as we move right, x-coordinate increases and as we move down, y-coordinate increases.
And alpha (transparency) takes values from 0-1, 0 corresponding to full transparency and 1 corresponding to no transparency.


  The functions defined are that the event listeners would call on recording a mouse event. We are defining functions with a parameters "e" which is a MouseEvent Object, this is because when an eventListener calls the functions, it sends the MouseEvent as an argument and if we don't define parameter "e", flash would detect an Argument Mismatch Error.


To download the source files, clik here (movement.fla).
 This tutorial can be extended to buttons and graphics too as they carry almost the same properties.
In case of doubts or any problems faced while trying out this tutorial, feel free to leave a comment below.