从Flash调用jQuery函数 [英] Calling jQuery Function from Flash

查看:137
本文介绍了从Flash调用jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在动作脚本中使用ExternalInterface.call()方法从Flash调用外部JS函数。该函数应该打开一个已经写在jQuery中的模式窗口。我的问题有两个:


  1. 如何打开这个模式窗口,而不需要将动作附加到链接上?我只想让窗口打开并传递URL。
  2. 有没有更好的方法来做到这一点?

(代码如下 - 我只包含了相关的函数,如果需要更多,请告诉我)

ActionScript:

  import flash.external.ExternalInterface; 

函数openMapWindowLink(thingName):void {
ExternalInterface.call(openMapWindow,locationURL);

jQuery: b

  //将动作添加到一个链接(这个工作)
函数initAjaxPopups(){
$('。ajax-popup' ).simpleLightbox({
closeLink:'a.btn-close,a.close-popup',
faderOpacity:0.7,
faderBackground:'#000',
href: true,
onClick:null
});
}

//使用url打开灯箱(不能正常工作)
函数openMapWindow(locationURL){
// alert('Clicked'+ locationURL );
$ simpleLightbox({
closeLink:'a.btn-close,a.close-popup',
faderOpacity:0.7,
faderBackground:'#000',
href:locationURL,
onClick:null
});


$ b / * ajax lightbox插件* /
jQuery.fn.simpleLightbox = function(_options){
var _options = jQuery.extend {
lightboxContentBlock:'.lightbox',
faderOpacity:0.8,
faderBackground:'#ffffff',
closeLink:'a.close-btn,a.cancel',
href:true,
onClick:null
},_ options);


var _popupCounter = 1;

return this.each(function(i,_this){
var _this = jQuery(_this);
if(!_options.href)
_this.lightboxContentBlock = _options.lightboxContentBlock;
else _this.lightboxContentBlock = _this.attr('href');
if(_this.lightboxContentBlock!=''&&& _this.lightboxContentBlock.length> 1){
_this.faderOpacity = _options.faderOpacity;
_this.faderBackground = _options.faderBackground;
_this.closeLink = _options.closeLink;
var _fader;
var _lightbox = $($ this_lightboxContentBlock);
if(!jQuery('div.lightbox-fader')。length)
_fader = $('body')。append('< div class =lightbox );

_fader = jQuery('div.lightbox-fader');
_lightbox.css({
'zIndex' :999
});
_fader.css({
opacity:_this.faderOpacity,
backgroundColor:_this.faderBackground,
display:'none',
position:'absolute',
top :0,
left:0,
zIndex:998,
textIndent:-9999
})。text('& nbsp;');
_lightbox.shownFlag = false;
if(jQuery.isFunction(_options.onClick)){
_options.onClick.apply(_this);
}

var _popupURL = _this.attr('href');
if(jQuery('div [rel * =''+ _ popupURL +'')')。length == 0){
$ .ajax({
url:_popupURL,
global:false,
类型:GET,
dataType:html,
success:function(msg ){
//附加加载弹出
_lightbox = $(msg);
_lightbox.attr('rel',_ popupURL).css({
zIndex:999,
位置:'绝对',
显示:'block',
top:-9999,
剩下:-9999
});
_lightbox.attr('id','ajaxpopup'+ _ popupCounter);
jQuery('body')。append(_lightbox);

// init js for lightbox
if(typeof initPopupJS ==function){
initPopupJS(_lightbox);
}
_popupCounter ++;

附加关闭事件
jQuery(_this.closeLink,_lightbox).click(function(){
_lightbox.fadeOut(400,function(){
_fader.fadeOut(300);
_scroll = false;
});
return false;
});

//显示lightbox
_lightbox.hide();
_lightbox.shownFlag = true;
jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
_fader.fadeIn(300,function(){
_lightbox.fadeIn(400);
jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
if(typeof VSA_handleResize == ='function'){
VSA_handleResize();
}
});
},
错误:函数(msg){
alert('ajax error');
返回false;
}
});
} else {
_lightbox = jQuery('div [rel * =''+ _ popupURL +'''');
_lightbox.hide();
_lightbox.shownFlag = true;
jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
_fader.fadeIn(300,function(){
_lightbox.fadeIn(400);
jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
if(typeof VSA_handleResize == ='function'){
VSA_handleResize();
}
});
}
返回false;
});
jQuery(_this.closeLink).click(function(){
_lightbox.fadeOut(400,function(){
_fader.fadeOut(300);
_scroll = false;
});
return false;
});
_fader.click(function(){
_lightbox.fadeOut(400,function(){
_fader.fadeOut(300);
});
return false ;
});
var _scroll = false;
jQuery.fn.simpleLightbox.positionLightbox = function(_lbox){
if(!_ lbox.shownFlag)return false;
var _height = 0;
var _width = 0;
var _minWidth = $('body> div:eq(0)')。outerWidth();
if(window.innerHeight){
_height = window.innerHeight;
_width = window.innerWidth;
} else {
_height = document.documentElement.clientHeight;
_width = document.documentElement.clientWidth;
}
var _thisHeight = _lbox.outerHeight();
var _page = $('body');
if(_lbox.length){
if(_width <_minWidth){_fader.css('width',_ minWidth);} else {_fader.css('width','100%') ;}
if(_height> _page.innerHeight())_fader.css('height',_ height); else _fader.css('height',_ page.innerHeight());
if(_height> _thisHeight){
if($ .browser.msie&& $ .browser.version< 7){
_lbox.css({
position:'absolute',
top:(document.documentElement.scrollTop +(_height - _thisHeight)/ 2)+px
});
} else {
_lbox.css({
position:'fixed',
top:((_height - _lbox.outerHeight())/ 2)+px
});
}
}
else {
var _fh = parseInt(_fader.css('height'));
if(!_scroll){
if(_fh - _thisHeight> parseInt($(document).scrollTop())){
_fh = parseInt($(document).scrollTop() )
_scroll = _fh;
} else {
_scroll = _fh - _thisHeight;

$ b $ _lbox.css({
position:'absolute',
top:_scroll
}); $ _
$ b if(_width> _lbox.outerWidth())_lbox.css({left:((__width - _lbox.outerWidth())/ 2 + 10)+px})
else _lbox.css({position:'absolute',left:0});


$ b $ jQuery(window).resize(function(){
if(_lightbox.is(':visible'))
jQuery .fn.simpleLightbox.positionLightbox(_lightbox);
});
jQuery(window).scroll(function(){
if(_lightbox.is(':visible'))
jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
});

jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
$(document).keydown(function(e){
if(!e)evt = window.event;
if(e.keyCode == 27){
_lightbox .fadeOut(400,function(){
_fader.fadeOut(300);
});
}
});
}
});

$ / code>


解决方案

是不是一个链接它应该是

$ $ $ $ $ $ $ $ $。simpleLightbox({...})/与。在
之后

如果不行,你可以改变lightBox的插件源代码,但是这可能会很麻烦希望稍后更新到新版本。



这是一个解决方法,应该可以工作:

 < a class =hiddenid =dummylinkhref =#>& nbsp< / a> 

//准备就绪
$('#dummylink')。simpleLightbox({...});

$ b函数openMapWindow(locationURL){
$(#dummylink)。attr(href,locationURL).trigger('click');
}


I'm trying to call an external JS function from flash using the ExternalInterface.call() method in action script. The function should open a modal window that has been written in jQuery. My problem is two fold:

  1. How do I open this modal window without attaching the action to a link? I just want the window open and to pass in the URL.
  2. Is there a better way to do this?

(Code below - I only included the relevent functions. If more if needed, let me know)

ActionScript:

import flash.external.ExternalInterface;

function openMapWindowLink(thingName):Void {
  ExternalInterface.call("openMapWindow",locationURL);
}

jQuery:

// Add the action to a link (this works)
function initAjaxPopups() {
    $('.ajax-popup').simpleLightbox({
        closeLink:'a.btn-close, a.close-popup',
        faderOpacity: 0.7,
        faderBackground: '#000',
        href:true,
        onClick: null
    });
}

// Open the lightbox from flash with url (not working correctly)
function openMapWindow(locationURL) {
    //alert('Clicked '+locationURL);
    $simpleLightbox({
        closeLink:'a.btn-close, a.close-popup',
        faderOpacity: 0.7,
        faderBackground: '#000',
        href:locationURL,
        onClick: null
    });

}

/* ajax lightbox plugin */
jQuery.fn.simpleLightbox = function(_options){
    var _options = jQuery.extend({
        lightboxContentBlock: '.lightbox',
        faderOpacity: 0.8,
        faderBackground: '#ffffff',
        closeLink:'a.close-btn, a.cancel',
        href:true,
        onClick: null
    },_options);


    var _popupCounter = 1;

    return this.each(function(i, _this){
        var _this = jQuery(_this);
        if (!_options.href)
            _this.lightboxContentBlock = _options.lightboxContentBlock;
        else _this.lightboxContentBlock = _this.attr('href');
        if (_this.lightboxContentBlock != '' && _this.lightboxContentBlock.length > 1) {
            _this.faderOpacity = _options.faderOpacity;
            _this.faderBackground = _options.faderBackground;
            _this.closeLink = _options.closeLink;
            var _fader;
            var _lightbox = $(_this.lightboxContentBlock);
            if (!jQuery('div.lightbox-fader').length)
                _fader = $('body').append('<div class="lightbox-fader"></div>');

            _fader = jQuery('div.lightbox-fader');
            _lightbox.css({
                'zIndex':999
            });
            _fader.css({
                opacity:_this.faderOpacity,
                backgroundColor:_this.faderBackground,
                display:'none',
                position:'absolute',
                top:0,
                left:0,
                zIndex:998,
                textIndent: -9999
            }).text('&nbsp;');
            _lightbox.shownFlag = false;
            _this.click(function(){
                if (jQuery.isFunction(_options.onClick)) {
                    _options.onClick.apply(_this);
                }

                var _popupURL = _this.attr('href');
                if(jQuery('div[rel*="'+_popupURL+'"]').length == 0) {
                    $.ajax({
                        url: _popupURL,
                        global: false,
                        type: "GET",
                        dataType: "html",
                        success: function(msg){
                            // append loaded popup
                            _lightbox = $(msg);
                            _lightbox.attr('rel',_popupURL).css({
                                zIndex:999,
                                position:'absolute',
                                display:'block',
                                top: -9999,
                                left: -9999
                            });
                            _lightbox.attr('id','ajaxpopup'+_popupCounter);
                            jQuery('body').append(_lightbox);

                            // init js for lightbox
                            if(typeof initPopupJS == "function"){
                                initPopupJS(_lightbox);
                            }
                            _popupCounter++;

                            // attach close event
                            jQuery(_this.closeLink, _lightbox).click(function(){
                                _lightbox.fadeOut(400, function(){
                                    _fader.fadeOut(300);
                                    _scroll = false;
                                });
                                return false;
                            });

                            // show lightbox
                            _lightbox.hide();
                            _lightbox.shownFlag = true;
                            jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
                            _fader.fadeIn(300, function(){
                                _lightbox.fadeIn(400);
                                jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
                                if(typeof VSA_handleResize === 'function') {
                                    VSA_handleResize();
                                }
                            });
                        },
                        error: function(msg){
                            alert('ajax error');
                            return false;
                        }
                    });
                } else {
                    _lightbox = jQuery('div[rel*="'+_popupURL+'"]');
                    _lightbox.hide();
                    _lightbox.shownFlag = true;
                    jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
                    _fader.fadeIn(300, function(){
                        _lightbox.fadeIn(400);
                        jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
                        if(typeof VSA_handleResize === 'function') {
                            VSA_handleResize();
                        }
                    });
                }
                return false;
            });
            jQuery(_this.closeLink).click(function(){
                _lightbox.fadeOut(400, function(){
                    _fader.fadeOut(300);
                    _scroll = false;
                });
                return false;
            });
            _fader.click(function(){
                _lightbox.fadeOut(400, function(){
                    _fader.fadeOut(300);
                });
                return false;
            });
            var _scroll = false;
            jQuery.fn.simpleLightbox.positionLightbox = function (_lbox) {
                if(!_lbox.shownFlag) return false;
                var _height = 0;
                var _width = 0;
                var _minWidth = $('body > div:eq(0)').outerWidth();
                if (window.innerHeight) {
                    _height = window.innerHeight;
                    _width = window.innerWidth;
                } else {
                    _height = document.documentElement.clientHeight;
                    _width = document.documentElement.clientWidth;
                }
                var _thisHeight = _lbox.outerHeight();
                var _page = $('body');
                if (_lbox.length) {
                    if (_width < _minWidth) {_fader.css('width',_minWidth);} else {_fader.css('width','100%');}
                    if (_height > _page.innerHeight()) _fader.css('height',_height); else _fader.css('height',_page.innerHeight());
                    if (_height > _thisHeight) {
                        if ($.browser.msie && $.browser.version < 7) {
                            _lbox.css({
                                position:'absolute',
                                top: (document.documentElement.scrollTop + (_height - _thisHeight) / 2)+"px"
                            });
                        } else {
                            _lbox.css({
                                position:'fixed',
                                top: ((_height - _lbox.outerHeight()) / 2)+"px"
                            });
                        }
                    }
                    else {
                        var _fh = parseInt(_fader.css('height'));
                        if (!_scroll) {
                        if (_fh - _thisHeight > parseInt($(document).scrollTop())) {
                                _fh = parseInt($(document).scrollTop())
                                _scroll = _fh;
                            } else {
                                _scroll = _fh - _thisHeight;
                            }
                        }
                        _lbox.css({
                            position:'absolute',
                            top: _scroll
                        });
                    }
                    if (_width > _lbox.outerWidth()) _lbox.css({left:((_width - _lbox.outerWidth()) / 2 + 10) + "px"});
                    else _lbox.css({position:'absolute',left: 0});
                }
            }

            jQuery(window).resize(function(){
                if (_lightbox.is(':visible'))
                    jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
            });
            jQuery(window).scroll(function(){
                if (_lightbox.is(':visible'))
                    jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
            });

            jQuery.fn.simpleLightbox.positionLightbox(_lightbox);
                $(document).keydown(function (e) {
                if (!e) evt = window.event;
                if (e.keyCode == 27) {
                    _lightbox.fadeOut(400, function(){
                        _fader.fadeOut(300);
                    });
                }
            });
        }
    });
}

解决方案

If attaching lightBox to something which isn't a link it should be

$.simpleLightbox({...})  // with the "." after $

IF that doesnt work you could alter the lightBox plugin source, but this could be troublesome if you wish to update to a newer versions later.

This is a workaround that should work:

<a class="hidden" id="dummylink" href="#">&nbsp</a>

//on ready
$('#dummylink').simpleLightbox({...});


function openMapWindow(locationURL) {
   $("#dummylink").attr("href", locationURL).trigger('click');
}

这篇关于从Flash调用jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆