It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Terminating SWF with SWFObject

Terminating SWF with SWFObject

Postby Colevora on Sat Aug 13, 2011 8:30 pm

Hi I'm currently working on a video gallery having videos "pop up" and displayed in a player in a lightbox fashion. I would also like for the video and videoplayers to be revealed behind an opening curtain, which is a transparent swf file floated on top of the flash player. The code appears below:

Code: Select all
jQuery(function(){
var $=jQuery;
var swfID = "video_overlay";
var swftop = "curtain_overlay";

if(!document.getElementById("vcurtain")){
    $("body").append($("<div id='voverlay'></div>"));
    $("#voverlay").append($("<div id = 'vcontainer'><div id = 'vcurtain'></div></div>"));
}

$("#videogallery a[rel]").overlay({
    api:true,

    expose: (0?{
        color:'#424542',
        loadSpeed:400,
        opacity:0
    }:null),

    effect:"apple",

    onClose: function(){
        swfobject.removeSWF(swfID);
    },

    // VIDEO OVERLAY SECTION //
    onBeforeLoad: function(){
        // check and create overlay contaner for fottage
        var c = document.getElementById(swfID);
        if(!c){
            var d = $("<div></div>");
            d.attr({id: swfID});
            $("#vcontainer").append(d);
        };

        var wmkText="© 2011 BORKH";
        var wmkLink="javascript:remove();";
        c = wmkText? $('<div></div>'):0;
        if (c) {
            c.css({
                position:'absolute',
                right:'38px',
                top:'38px',
                padding:'0 0 0 0'
            });
            $("#vcontainer").append(c);
        };

        // for IE use iframe
        if (c && document.all){
            var f = $('<iframe src="javascript:false"></iframe>');
            f.css({
                position:'absolute',
                left:0,
                top:0,
                width:'100%',
                height:'100%',
                filter:'alpha(opacity=0)'
            });

            f.attr({
                scrolling:"no",
                framespacing:0,
                border:0,
                frameBorder:"no"
            });

            c.append(f);
        };

        var d = c? $(document.createElement("A")):c;
        if(d){
            d.css({
                position:'relative',
                display:'block',
                'background-color':'',
                color:'#626d73',
                'font-family': 'RegisterSansBTNDmRegular, Helvetica, Arial',
                'font-size':'11px',
                'font-weight':'normal',
                'font-style':'normal',
                'text-decoration': 'none',
                padding:'1px 5px',
                opacity:.7,
                filter:'alpha(opacity=70)',
                width:'auto',
                height:'auto',
                margin:'0 0 0 0',
                outline:'none'

            });
            d.attr({href:wmkLink});
            d.html(wmkText);
            d.bind('contextmenu', function(eventObject){
                return false;
            });

            c.append(d);
        }


        // create SWF
        var src = this.getTrigger().attr("href");

        if (typeof(d)!='number' && (!c || !c.html || !c.html())) return;

        if (false){
            var this_overlay = this;
            // if local
            window.videolb_complite_event = function (){ this_overlay.close() };
            // if youtoube
            window.onYouTubePlayerReady = function (playerId){
                var player = $('#'+swfID).get(0);
                if (player.addEventListener) player.addEventListener("onStateChange", "videolb_YTStateChange");
                else player.attachEvent("onStateChange", "videolb_YTStateChange");
                window.videolb_YTStateChange = function(newState){
                    if (!newState) this_overlay.close()
                }
            }
        }

        swfobject.createSWF(
            { data:src, width:"100%", height:"100%", wmode:"opaque" },
            { allowScriptAccess: "always", allowFullScreen: true, FlashVars: (false?"complete_event=videolb_complite_event()&enablejsapi=1":"") },
            swfID
        );


        // CURTAIN OVERLAY SECTION //
    var s = document.getElementById(swftop);
        if(!s){
            var t = $("<div></div>");
            t.attr({id: swftop});
            $("#vcurtain").append(t);
        };

        s = wmkText? $('<div></div>'):0;
        if (s) {
            $("#vcontainer").append(s);
        };

        // for IE use iframe
        if (s && document.all){
            var h = $('<iframe src="javascript:false"></iframe>');
            h.css({
                position:'absolute',
                left:0,
                top:0,
                width:'100%',
                height:'100%',
                filter:'alpha(opacity=0)'
            });

            h.attr({
                scrolling:"no",
                framespacing:0,
                border:0,
                frameBorder:"no"
            });

            s.append(h);
        };

        var t = s? $(document.createElement("B")):s;
        if(t){
            t.bind('contextmenu', function(eventObject){
                return false;
            });
            swfobject.removeSWF("swftop");
            s.append(t);
        }

        // create SWF

        if (typeof(t)!='number' && (!s || !s.html || !s.html())) return;

        if (false){
            var this_overlay = this;
            // if local
            window.videolb_complite_event = function (){ this_overlay.close() };
        }

        swfobject.createSWF(
            { data:"http://www.borkh.co.uk/video/data/curtain.swf", width:"100%", height:"100%", wmode:"transparent" },
            { allowScriptAccess: "always", allowFullScreen: true, FlashVars: (false?"complete_event=videolb_complite_event()&enablejsapi=1":"") },
            swftop
        );
    }
}); });

I however run into the problem that it's not possible to interact with the player underneath the curtain animation... This is because you cannot interact with a swf file through another swf file although it is transparent. I was therefore thinking that the curtain animation using flash could upon completion tell javascript to remove itself by loading a function which could look like:
Code: Select all
function remove() {
swfobject.removeSWF(swftop);}

I am however not sure where to place this function in the code for it to have the right effect.. I've tried calling it placed outside the jQuary function with a button, but it doesn't seem to remove the curtain swf. If you have any suggestions to how i terminate the swf file (remove it completely) please help.

Regards Cole
Colevora
 
Posts: 1
Joined: Sat Aug 13, 2011 8:19 pm

Who is online

Users browsing this forum: No registered users and 4 guests