Return to Snippet

Revision: 25214
at April 14, 2010 13:58 by mcarneiro


Updated Code
// *** inside javascript **
function handleWheel(event) {
	var app = document.getElementById('flashSite');
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = -(event.wheelDelta/60); 
	} else if (event.detail) {
		delta = event.detail;
	}
	var o = {
		x: event.screenX,
		y: event.screenY,
		delta: delta,
		ctrlKey: event.ctrlKey,
		altKey: event.altKey,
		shiftKey: event.shiftKey
	};
	if (app && typeof(app.handleWheel) == 'function')
		app.handleWheel(o);
}

// on page onload
if(!(document.attachEvent)) {
	window.addEventListener("DOMMouseScroll", handleWheel, false);
	window.addEventListener('mousewheel', handleWheel, false);
	document.addEventListener('mousewheel', handleWheel, false);
}

// *** inside flash ***
if(ExternalInterface.available){
	ExternalInterface.addCallback("handleWheel", handleWheel);
}

// method that will be accessed from dispatched javascript events
public function handleWheel(event:Object): void {
	var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
		event.x, event.y, this,
		event.ctrlKey, event.altKey, event.shiftKey,
		false, -Number(event.delta));
	this.dispatchEvent(mEvent); // where "this" is the documentClass. Can be "stage" too
}

Revision: 25213
at March 23, 2010 14:22 by mcarneiro


Updated Code
// *** inside javascript **
function handleWheel(event) {
	var app = document.getElementById('flashSite');
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = -(event.wheelDelta/60); 
	} else if (event.detail) {
		delta = event.detail;
	}
	var o = {
		x: event.screenX,
		y: event.screenY,
		delta: delta,
		ctrlKey: event.ctrlKey,
		altKey: event.altKey,
		shiftKey: event.shiftKey
	};
	if (app)
		app.handleWheel(o);
}

// on page onload
if(!(document.attachEvent)) {
	window.addEventListener("DOMMouseScroll", handleWheel, false);
	window.addEventListener('mousewheel', handleWheel, false);
	document.addEventListener('mousewheel', handleWheel, false);
}

// *** inside flash ***
if(ExternalInterface.available){
	ExternalInterface.addCallback("handleWheel", handleWheel);
}

// method that will be accessed from dispatched javascript events
public function handleWheel(event:Object): void {
	var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
		event.x, event.y, this,
		event.ctrlKey, event.altKey, event.shiftKey,
		false, -Number(event.delta));
	this.dispatchEvent(mEvent); // where "this" is the documentClass. Can be "stage" too
}

Revision: 25212
at March 23, 2010 14:13 by mcarneiro


Initial Code
// *** inside javascript ***
function handleWheel(event) {
	var app = $('#flashSite')[0];
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = -(event.wheelDelta/60); 
	} else if (event.detail) {
		delta = event.detail;
	}
	var o = {
		x: event.screenX,
		y: event.screenY,
		delta: delta,
		ctrlKey: event.ctrlKey,
		altKey: event.altKey,
		shiftKey: event.shiftKey
	};
	if (app)
		app.handleWheel(o);
}

// on page onload
if(!(document.attachEvent)) {
   	window.addEventListener("DOMMouseScroll", handleWheel, false);
}
window.onmousewheel = document.onmousewheel = handleWheel;

// *** inside flash ***
if(ExternalInterface.available){
	ExternalInterface.addCallback("handleWheel", handleWheel);
}

// method that will be accessed from dispatched javascript events
public function handleWheel(event:Object): void {
	var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
		event.x, event.y, this,
		event.ctrlKey, event.altKey, event.shiftKey,
		false, -Number(event.delta));
	this.dispatchEvent(mEvent); // where "this" is the documentClass. Can be "stage" too
}

Initial URL

                                

Initial Description

                                

Initial Title
Click wheel fix for mac (safari + firefox)

Initial Tags
mac, browser, flash

Initial Language
JavaScript