MouseEvents can be captured from Javascript and can be used for some amazing things in Flex. I have used ExternalInterface and FlexBridge to capture mouse positions from a html page to rotate a 3D Flex Cube as shown below:

flexbox

The demo of the same can be seen here

The following javascript is used to capture the mouse move positions:

document.onmousemove = getMouseXY;

var flexApp;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function initCallback() {
flexApp = FABridge.mousecapture.root()
alert("initCallback");
}

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
document.Show.MouseX.value = tempX
document.Show.MouseY.value = tempY
return true
}

function getMousex(){
return tempX
}

function getMousey(){
return tempY
}

The mouse positions can be recieved in Flex by calling getMousex() and getMousey() methods using External Interface.

Related posts:

Share