码迷,mamicode.com
首页 > 其他好文 > 详细

as3 打开窗口类

时间:2016-06-03 01:16:22      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

 package FlashCode.utils{
 
 import flash.display.Sprite;
 import flash.net.URLRequest;
 import flash.net.navigateToURL;
 import flash.external.ExternalInterface;
 
 public class openWindow {
  public function openWindow(url:String, window:String="_blank", features:String=""){
     
   var WINDOW_OPEN_FUNCTION:String = "window.open";
   var myURL:URLRequest = new URLRequest(url);   
   var browserName:String = getBrowserName();
   
   if(getBrowserName() == "Firefox"){
    ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
   }
   //If IE, 
   else if(browserName == "IE"){
    ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
    //ExternalInterface.call("function setWMWindow() {window.open(‘" + url + "‘);}");
   }
   //If Safari 
   else if(browserName == "Safari"){     
    navigateToURL(myURL, window);
   }
   //If Opera 
   else if(browserName == "Opera"){ 
    navigateToURL(myURL, window); 
   } else {
    navigateToURL(myURL, window);
   }
   
   /*Alternate methodology...
      var popSuccess:Boolean = ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features); 
   if(popSuccess == false){
    navigateToURL(myURL, window);
   }*/
    
  }
  private function getBrowserName():String{
   var browser:String;
   
   //Uses external interface to reach out to browser and grab browser useragent info.
   var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent;}");
  
    //  Debug.text += "Browser Info: [" + browserAgent + "]";
   
   //Determines brand of browser using a find index. If not found indexOf returns (-1).
   if(browserAgent != null && browserAgent.indexOf("Firefox") >= 0) {
    browser = "Firefox";
   } 
   else if(browserAgent != null && browserAgent.indexOf("Safari") >= 0){
    browser = "Safari";
   }    
   else if(browserAgent != null && browserAgent.indexOf("MSIE") >= 0){
    browser = "IE";
   }   
   else if(browserAgent != null && browserAgent.indexOf("Opera") >= 0){
    browser = "Opera";
   }
   else {
    browser = "Undefined";
   }
   return browser;
  }
 }
}

 

在as2的时代,只有onRelease下的getURL才会被认为是一次完整的点击,onPress就会被拦截

到了navigateToURL的时代,即便你监听一个MouseEvent.CLICK事件,他也会被拦截,原因我现在也不知道,谁知道的话可以跟帖

那么怎么解决as3弹出一个_blank不被拦截呢,3个条件

1.判断浏览器的版本,如果是firefox和其他什么opera啥的就直接navigateToURL,如果是IE的话就调用window.open
2.必须监听MouseEvent.CLICK事件,如果是MouseEvent.DOWN啥的我就不敢保证了
3.wmode属性必须设置成opaque,Transparent的话我没试过,大家可以试试,反正window肯定不行

这3个条件满足了,才能保证弹出的新页面不被拦截!!!!!!!!!!

as3 打开窗口类

标签:

原文地址:http://www.cnblogs.com/allonkwok/p/5554882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!