View Full Version : Detecting Mouse Click
06-20-2008, 02:10 PM
I'm trying to figure out how to get functionality like the Info Panel that the Flash IDE has. That panel is always updating with the location of the cursor, knows the color/alpha of the element under the cursor and if you select something the text boxes change to show information about the selected object. After looking through the help references I cannot see any functionality that explains how this is done.
I've played with using a setInterval and enterFrame on my windowSWF and that does what I want but it doesn't interact very well with the Actions panel. And sometimes the cursor just acts weird as the panel is running its code. Often times the behavior goes away if I click on the stage though so I'm tempted to stick a mouse click command in there for a spot off to the edge of the stage.
So does anybody know the proper way to detect when an element has been selected? Or at least point me to somewhere that explains it?
07-14-2008, 03:34 PM
I was researching this my self for a while and I think that there is no option to get 'select' event in JSFL.
07-14-2008, 04:02 PM
You were pretty close to having it work right. I couldn't get it to work until I figured out how to get MMExecute to return variables. What you need to do is declare a variable in your jsfl, set its value and then at the very end of that jsfl script just type the name of the variable. That will return the value of your jsfl variable through MMExecute and then you can use the data in your .swf. Here's some example code:
var xLoc = "var loc = fl.tools.penLoc.x;\n";
xLoc +="loc;"; //Returns loc (fl.tools.penLoc.x)
var yLoc = "var loc = fl.tools.penLoc.y;\n";
yLoc +="loc;"; //Returns loc (fl.tools.penLoc.y)
var mySelection = "var loc = fl.tools.penLoc;\n";
mySelection +="var selection = fl.getDocumentDOM().selection;\n";
mySelection +="var selectionToDisplayInSWF = selection;\n";
mySelection +="selectionToDisplayInSWF;";//***Returns the first element in the selection array***
position.text = "x: " + MMExecute(xLoc) + ", y: " + MMExecute(yLoc);
mytxt.text = MMExecute(mySelection);
*In order for this to work you'll need two textfields... position and mytxt.
07-16-2008, 05:39 PM
Well, your code does what it advertises but doesn't really solve the problems I have.
It does give the location of the cursor which is handy to have. But it doesn't really detect the mouse click, it more or less just returns what is selected. This is easily accomplished and I actually had this working. Plus the problems with the IDE acting strangely with the enterFrame event such as the cursor constantly changing states and the inability to double-click objects on the stage is still there.
So far my experience is that extensions (or at least mine) do not behave well with the IDE when using enterFrame events. That was why I was hoping for a way to just detect the click and then run my function with that click.
Being able to see the code for the Info panel would be wonderful to solve this problem.
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.