首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Flash >

Flex设置flash在html中所遇到的种种有关问题

2013-12-30 
Flex设置flash在html中所遇到的种种问题if(!(document.all)) {if (document.addEventListener) {window.ad

Flex设置flash在html中所遇到的种种问题
if(!(document.all)) { if (document.addEventListener) { window.addEventListener("DOMMouseScroll", onMouseWheelHandler, false); } window.onmousewheel = document.onmousewheel = this.onMouseWheelHandler; //Opera/Chrome }function getFlashMovieObject(movieName){if (window.document[movieName]) {return window.document[movieName];}if (navigator.appName.indexOf("Microsoft Internet") == -1) {if (document.embeds && document.embeds[movieName])return document.embeds[movieName];}else {return document.getElementById(movieName);}}function onMouseWheelHandler(e){ var o = {x: e.screenX, y: e.screenY, delta: e.wheelDelta ? e.wheelDelta : -e.detail, ctrlKey: e.ctrlKey, altKey: e.altKey, shiftKey: e.shiftKey}; var vflash = getFlashMovieObject("${application}"); vflash.handleWheel(o); };

?通过添加该段js脚本可以使得js可以调用flash为js注册的handleWheel方法.

?

在flex中我们需要添加该注册方法,在swf构建完毕后,添加如下内容

?

ExternalInterface.addCallback( "handleWheel" , handleWheel);  

?实现handleWheel方法

public function handleWheel(event:Object):void{var obj:InteractiveObject = null;var objects:Array = this.getObjectsUnderPoint(new Point(event.x, event.y));for (var i:int = objects.length - 1; i >= 0; i--) {if (objects[i] is InteractiveObject) {obj = objects[i] as InteractiveObject;break;} else {if (objects[i] is Shape && (objects[i] as Shape).parent) {obj = (objects[i] as Shape).parent;break;}}}if (obj) {var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false, event.x, event.y, obj, event.ctrlKey, event.altKey, event.shiftKey,false, Number(event.delta) >0 ? 1:-1);obj.dispatchEvent(mEvent);}}

?

?

就可以实现在非window模式下 FF/Chrome 滚轮事件的响应了

问题2描述: wmode 模式的选用 ,导致鼠标滚轮无效-FireFox特殊处理

进行问题1的解决方法后,会发现在FireFox下仍然无效,解决方法是在flex中注册js调用方法前加入:

?

Security.allowDomain("*");Security.allowInsecureDomain("*"); 
?同意FireFox的js可以调用访问该域下swf的方法.

?

问题3描述: wmode 模式的选用 ,导致ComboBox无法打开使用的处理方式

由于鼠标的滚轮事件会通过js来传递给ComboBox,原combobox的鼠标监听事件无法使用,会导致在combobox打开的状态下,会认为js传来的事件是combobox的外部事件,那么combobox会自动关闭listbase.

解决方法,自己动手写一个combobox,将combbox的listbase打开关闭状态记录下来.当在接到外部js的滚轮事件时 && 并且 combobox的listbase处理打开状态,那么手动处理combobox的滚动.

代码如下:

?

package com.loyo.ui{import flash.utils.Dictionary;import mx.controls.ComboBox;import mx.events.DropdownEvent;public class SelfComboBox extends ComboBox{public static var selfComboBoxNum:int = 0;public static var selfComboBoxDict:Dictionary = new Dictionary();public static function getSCombobox(id:String):SelfComboBox{return selfComboBoxDict[id];}public static function setSelfComboBox(id:String,scombobox:SelfComboBox):void{selfComboBoxDict[id] = scombobox;}public var isOpen:Boolean = false;public function SelfComboBox(){super();this.id = "scombobox_"+selfComboBoxNum;selfComboBoxNum++;setSelfComboBox(this.id,this);addEventListener(DropdownEvent.OPEN,onDropdownOpen);addEventListener(DropdownEvent.CLOSE,onDropdownClose);}public function onDropdownOpen(event:DropdownEvent):void{trace(" SelfComboBox isOpen :  true" );this.isOpen = true;}public function onDropdownClose(event:DropdownEvent):void{trace(" SelfComboBox isOpen :  false" );this.isOpen = false;}public function doMouseWheelByJS(delta:Number):void{if(isOpen){if(delta > 0){if(dropdown.selectedIndex > 0){dropdown.selectedIndex--;}}else{dropdown.selectedIndex++;}dropdown.scrollToIndex(dropdown.selectedIndex);}}}}
?

?

----待续.. 有急事

问题5描述: wmode 模式的选用 ,IFrame嵌入swf包装页面html时,如何解决Iframe的滚轮不影响主页面

?

?

热点排行