Skip to main content
Srihari_Ch
Known Participant
December 29, 2008
Question

AS3 code for Mouse Event

  • December 29, 2008
  • 5 replies
  • 965 views
Hi,

I had uploaded jpeg file onto the stage using File->Import.

Now, how to access the mouse-events using AS3.0?

i.e., when we click with mouse on the stage
it should display the x and y co-ordinates of the point being clicked.
These x and y coordinates must be displayed in text-boxes provided down on the same stage.

Please reply me
This topic has been closed for replies.

5 replies

Ned Murphy
Legend
January 2, 2009
The posting with the example should work for you as long as you create a movieclip called tooltips (which would be your popup... you can name it whatever you like, but tooltips was used as an example). Inside tooltips would be textfields which you will assign whatever text you wish to assign... below I use textfieldx and textfieldy as the instance names for these textfields

function showClip(evt:MouseEvent) {
tooltips.x = evt.target.x + evt.target.width;
tooltips.y = evt.target.y - evt.target.height;
tooltips.textfieldx.txt = "X: " + evt.localX;
tooltips.textfieldy.txt = " Y: " +evt.localX;
tooltips.visible = true
}
Marghoob Sulemaan
Inspiring
January 2, 2009
You can do show/hide movieclip on mouseover. get your box position and assign to the popup (tooltip movieclip).

see this...
not tested. but it should work.


import flash.events.MouseEvent;
function showClip(evt:MouseEvent) {
tooltips.x = evt.target.x + evt.target.width;;
tooltips.y = evt.target.y - evt.target.height;
tooltips.visible = true
}
function hideClip(evt:MouseEvent) {
tooltips.visible = false;
}

box.addEventListener(MouseEvent.MOUSE_OVER, showClip);
box.addEventListener(MouseEvent.MOUSE_OUT, hideClip);

I assume you'll create two movieclips named: box and tooltips

Srihari_Ch
Known Participant
January 2, 2009
The code you had given is not working.

Please, once try it.

Also, I need a pop-up and a message in pop-up when the object is clicked.

Please help me....
Srihari_Ch
Known Participant
December 30, 2008


Continued......

Presently, I am using Action Script 3.0 using Flash 9.
But, I couldn't understand the code present in above link.

Please explain me..
Srihari_Ch
Known Participant
December 30, 2008
Thanks a lot for your help......

As I am new to the AS3 platform, You had helped me....


Now I need to display these x and y co-ordinate values in a pop-up when clicked.

You can see the sample output here for Mouse_RollOver event in the below link:
http://www.flashdesignerzone.com/tutorials/t1025.php

Marghoob Sulemaan
Inspiring
December 29, 2008
This could help you.

import flash.events.MouseEvent;
function listener(evt:MouseEvent) {
trace(evt.localX, evt.localX);
//text_txt.text = "X: " + evt.localX + " Y: " +evt.localX;
}

stage.addEventListener(MouseEvent.CLICK, listener);
//box.addEventListener(MouseEvent.CLICK, listener);