Flash Buff
flashbuff.blogspot.com
flashbuff.blogspot.com
Sample Cursor |
Code ::import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.MOUSE_MOVE,cur_fn);
function cur_fn(e:MouseEvent)
{
Mouse.hide();
cur_mc.x=stage.mouseX;
cur_mc.y=stage.mouseY;
e.updateAfterEvent();
}
import flash.events.MouseEvent;Here, we are telling the flash movie to import the MouseEvent Class which contains events that we will be using in our movie.
stage.addEventListener(MouseEvent.MOUSE_MOVE,cur_fn);
We are assigning an EventListener at the stage level (root) to listen to the events and call the function "cur_fn" when a "MOUSE_MOVE" event is detected.
So whenever the mouse is moved, the event listener calls the "cur_fn" function with the appropriate MouseEvent Object as parameters.
function cur_fn(e:MouseEvent)Now that we know how to change the cursor in our flash movies, we can extend this knowledge to create much more advanced cursors with different states for click and drag (or) create a cursor with a trail (or) implement drag and drop functionality. The possibilities are endless ...
{
Mouse.hide();
cur_mc.x=stage.mouseX;
cur_mc.y=stage.mouseY;
e.updateAfterEvent();
}
Here, we are defining the "cur_fn" function that we instructed the eventListener to call when the mouse is moved on the stage...
Mouse.hide();
Here, we are calling the hide function which hides the default mouse cursor.
cur_mc.x=stage.mouseX;
cur_mc.y=stage.mouseY;
Here, we are assigning the x and y cordinates of the current position of the mouse, with respect to the stage and assigning them to the movieClip we created on the stage having the instance name "cur_mc".
This basically means that our movieclip takes the postition of the mouse.
e.updateAfterEvent();
Here, we are calling the updateAfterEvent function for the event "e", which is the mouse event that is passed by the eventListener.
The updateAfterEvent function basically updates/renders the screen every time the event occurs irrespective of the framerate of the movie.
This results in a smooth motion of the cursor. The benifits are much more prominent at lower frame rates.