When you think of the mouse cursor, the most common image you probably have is that of the classic arrow:
As you go about doing the things that you do on your computer, your mouse cursor will change. While this change may just seem cosmetic, the mouse cursor gives you important feedback on what is going on.
When you hover over a textfield, your cursor will change to one that enables text selection:
I could go on all day, but you get the gist of it. Depending on the context, your mouse cursor will change. You (and your users) rely on the mouse cursor to inform what is going on or what can be done.
In Flash, there are many cases where your mouse cursor will automatically change depending on what you are interacting with. You will see the link cursor when you are over a button. Giving focus to a text field, will give you the text selection cursor.
When you go beyond the default behaviors and scenarios, you will have to explicitly set the mouse cursor yourself. In this short tutorial, you will learn how to do just that!
First, you'll need to add the appropriate using statements to be able to use the MouseCursor class and, as part of the whole experience, the Mouse class:
Those values probably don't mean much, so the following table shows them pictorially:
There isn't much more to changing the cursor. To give you a complete example, below is some code that shows how to change the cursor when one hovers over an element:
When you hover over a textfield, your cursor will change to one that enables text selection:
[ for more gripping updates like this, friend me!! ]
This gives you an idea that you can probably click and start typing on your keyboard. One of the most important mouse cursors you see is the one that indicates a link is clickable: [ if it wasn't for this cursor, would you know you could click on the image? ]
If you did not see your cursor changing to the link cursor, you would probably not realize that you can click on it or manipulate it using your mouse.I could go on all day, but you get the gist of it. Depending on the context, your mouse cursor will change. You (and your users) rely on the mouse cursor to inform what is going on or what can be done.
In Flash, there are many cases where your mouse cursor will automatically change depending on what you are interacting with. You will see the link cursor when you are over a button. Giving focus to a text field, will give you the text selection cursor.
When you go beyond the default behaviors and scenarios, you will have to explicitly set the mouse cursor yourself. In this short tutorial, you will learn how to do just that!
The MouseCursor Class
In ActionScript 3, you have the MouseCursor class that allows you to specify the mouse cursor.First, you'll need to add the appropriate using statements to be able to use the MouseCursor class and, as part of the whole experience, the Mouse class:
- import flash.ui.MouseCursor;
- import flash.ui.Mouse;
- Mouse.cursor = MouseCursor.AUTO;
Those values probably don't mean much, so the following table shows them pictorially:
Cursors | Picture |
MouseCursor.ARROW | |
MouseCursor.AUTO | |
MouseCursor.BUTTON | |
MouseCursor.HAND | |
MouseCursor.IBEAM |
- package
- {
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- import flash.ui.MouseCursor;
- import flash.ui.Mouse;
- public class Main extends MovieClip
- {
- var mouseIsDown:Boolean = false;
- public function Main()
- {
- // constructor code
- myImage.addEventListener(MouseEvent.MOUSE_OVER, changeCursor);
- myImage.addEventListener(MouseEvent.MOUSE_OUT, resetCursor);
- }
- private function changeCursor(e:MouseEvent)
- {
- Mouse.cursor = MouseCursor.HAND;
- }
- private function resetCursor(e:MouseEvent)
- {
- Mouse.cursor = MouseCursor.ARROW;
- }
- }
- }
0 comments
একটি মন্তব্য পোস্ট করুন