Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,399 Programmers. There are 1,448 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Help Loading SWF in Javascript code

 
Reply to this topicStart new topic

Help Loading SWF in Javascript code, Help Loading SWF in Javascript code

edge57
post 23 Apr, 2008 - 03:39 PM
Post #1


New D.I.C Head

*
Joined: 23 Apr, 2008
Posts: 1



I need HELP!
I want load SWF files instead of JPG, or If possible Load either/both.
Right now it only works with JPG. Any help is greatly Appreciated.
Click here for Live Site: http://gar-de.com/lookbook.html
Here is my JS Code:
CODE
function init() {
    document.getElementById('nav-loading').style.display = "none";
    //document.getElementById('linkForward').style.display = "inline";
    document.getElementById('nav-Preview').style.display = "block";
}



// -------------------------------------------------------------




function winSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );
    var returnArray = new Array(myWidth, myHeight);
    //return returnArray;
    
    IMG = document.getElementById('magImg');

    
    if (myWidth > myHeight) {
        winner = "width";
        newWidth = myWidth;
        newHeight = (myWidth*612)/1006;
    } else {
        winner = "height";
        newHeight = myHeight;
        newWidth = (myHeight*1006)/612;
    }
    
    IMG.width = newWidth;
    IMG.height = newHeight;
    
    hDiff = IMG.height-myHeight;
    wDiff = IMG.width-myWidth;
    
    magDiv = document.getElementById('magazineHolder');

    var magW = magDiv.style.width;
    var magH = magDiv.style.height;
    
    
    if (hDiff>=0) {
        newT = 0-(hDiff/2);
    } else {
        //hd = Math.abs(hDiff);
        //newT = 0+(hd/2);
        IMG.height = myHeight;
        IMG.width = (myHeight*1006)/612;
        newT = 0;
    }
    if (wDiff>=0) {
        newL = 0-(wDiff/2);
    } else {
        //wd = Math.abs(wDiff);
        //newL = 0+(wd/2);
        IMG.width = myWidth;
        IMG.height = (myWidth*612)/1006;
        newL = 0;
    }
    
    magDiv.style.top = newT+"px";
    magDiv.style.left = newL+"px";
    
    
    var magT = magDiv.style.top;
    var magL = magDiv.style.left;
    
    
    
    var str = "w: "+myWidth+" <br /> h: "+myHeight+" <br />"+winner+"<br /> ";
    str = str+"<br /> hDiff: "+hDiff+" wDiff: "+wDiff;
    str = str+" <br /><br /> IMG w: "+IMG.width+" <br />IMG h: "+IMG.height;
    str = str+" <br /><br /> div t: "+magT+" <br />div l: "+magL;
    
    objDiv = document.getElementById('sizeDisplay');    
    objDiv.innerHTML=str;
    
    magDiv.style.display = "block";
    
    
    
}




// -----------------------------------------------------------------------------







function goHome() {
    if (currentStop>0) {
        /*
        document.getElementById('tocTXT').style.display = "none";
        document.getElementById('tocTXT').innerHTML = "";
        toggleNav();
        currentStop = 0;
        setFlips('b');
        */
        
        str = "";
        document.getElementById('tocTXT').style.display = "none";
        document.getElementById('tocTXT').innerHTML = "";
        toggleNav();
        currentImage = 100;
        for (n=0;n<4;n=n+1) {
            t = rate*n;
            window.setTimeout("flipForward();", t);
        }
            t = rate*5;
            window.setTimeout("finishGoHome();", t);
    }
}

function finishGoHome() {
    IMG = document.getElementById('magImg');
    currentStop = 0;
    currentImage = 1;
    IMG.src = "lookbook/"+currentImage+".jpg";
    
    document.getElementById('tocTXT').className = "intro";
    document.getElementById('linkBack').style.display = "none";
    str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
    showtxt();
    document.getElementById('nav-Preview').style.display = "block";
}






// -----------------------------------------------------------------------------










function flipper(direction) {
    document.getElementById('nav-Preview').style.display = "none";
    document.getElementById('tocTXT').style.display = "none";
    document.getElementById('tocTXT').innerHTML = "";
    toggleNav();
    
    if (direction == 'f') {
        currentStop++;
    } else {
        currentStop--;
    }
    
    if (allLoaded < 2) {
        //preloadImages(76,208);
        //allLoaded++;
    }
    setFlips(direction);
    
}

function setFlips(direction) {
    rate = 250;
    lenght = Math.abs(stops[currentStop]-currentImage);
    //lenght = 4;
    
    for (n=0;n<lenght;n=n+1) {
        t = rate*n;
        if (direction == 'f') {
            if (t == 0) {
                flipForward();
            } else {
                window.setTimeout("flipForward();", t);
            }
        } else {
            if (t == 0) {
                flipBackward();
            } else {
                window.setTimeout("flipBackward();", t);
            }
        }
    }
    
    
    t = rate*(lenght+2);
    window.setTimeout("toggleNav();",t);
    window.setTimeout("chngTxt();",t);
}


function flipForward() {
    //alert(currentImage);
    IMG = document.getElementById('magImg');
    currentImage++;
    IMG.src = "lookbook/"+currentImage+".jpg";
}

function flipBackward() {
    //alert(currentImage);
    IMG = document.getElementById('magImg');
    currentImage--;
    IMG.src = "lookbook/"+currentImage+".jpg";
}






// -----------------------------------------------------------------------------








/*function quickClose() {
    str = "";
    showtxt();
    toggleNav();
    currentImage = 200;
    for (n=0;n<7;n=n+1) {
        t = rate*n;
        window.setTimeout("flipForward();", t);
    }
    //t = rate*7;
    //window.setTimeout("document.getElementById('contactInfo').style.display = 'block';",t);
}


function quickOpen() {
    for (n=0;n<6;n=n+1) {
        t = rate*n;
        window.setTimeout("flipBackward();", t);
    }
    t = rate*7;
    window.setTimeout("flipToHouse();", t);
}

function flipToHouse() {
    currentImage = 1;
    currentStop = 0;
    IMG.src = "lookbook/"+currentImage+".jpg";
    document.getElementById('tocTXT').className = "intro";
    document.getElementById('linkBack').style.display = "none";
    str = "American Craft Celebrates the modern makers who shape the world around us. Presenting unkown innovators and established masters, American Craft connects the worlds of art, industry, architecture, fashion and design, bringing a fresh, new voice to the craft community.";
    showtxt();
    toggleNav();
}

function toggleMag() {
    if (currentImage>199) {
        document.getElementById('contactInfo').style.display = "none";
        quickOpen();
    } else {
        quickClose();
    }
}

*/



// -----------------------------------------------------------------------------







function chngTxt() {
    switch(stops[currentStop])    {
        case 1:
              document.getElementById('tocTXT').className = "intro";
              document.getElementById('linkBack').style.display = "none";
              document.getElementById('linkForward').style.display = "none";
              document.getElementById('nav-Preview').style.display = "block";
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
              break    
        case 6:
            document.getElementById('nav').style.display = "block";
            document.getElementById('nav-Preview').style.display = "none";
            document.getElementById('tocTXT').className = "norm";
            document.getElementById('linkForward').style.display = "inline";
            document.getElementById('linkBack').style.display = "inline";
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
              break
        case 10:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
              break
        case 14:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 18:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 22:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 26:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 30:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 34:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 38:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 42:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
              break
        case 46:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
              break
        case 50:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 54:
            str = "<p><a href='about.html'>About</a></p><p><a href='press.html'>Press</a></p><p><a href='lookbook.html'>Lookbook</a></p>";
            break
        case 58:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 62:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 66:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 58:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break            
        case 70:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break            
        case 74:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break            
        case 78:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 82:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break            
        case 90:
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break            
        case 94:
            document.getElementById('linkForward').style.display = "inline";
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
        case 98:
            document.getElementById('linkForward').style.display = "none";
            str = "<a href='about.html'>Bio</a><br /><a href='press.html'>Press</a><br /><a href='lookbook.html'>Lookbook</a><br /><a href='sales.html'>Sales</a><br />";
            break
    }
    showtxt();
}


function showtxt() {
    document.getElementById('tocTXT').innerHTML = str;
    document.getElementById('tocTXT').style.display = "block";
}




// -----------------------------------------------------------------------------





function toggleNav() {
    if (document.getElementById('nav').style.display == 'block') {
        linksActive = 0;
        document.getElementById('nav').style.display = 'none';
    } else {
        linksActive = 1;
        document.getElementById('nav').style.display = 'block';
    }
}






// -----------------------------------------------------------------------------






function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}





// -----------------------------------------------------------------------------






function redArrow(x,imgid) {
    IMG = document.getElementById(imgid);
    if (x == 'r') {
        IMG.src = "imgs/arrowR2-roll.png";
    } else {
        IMG.src = "imgs/arrowR2.png";
    }
}

function bigredArrow(x,imgid) {
    IMG = document.getElementById(imgid);
    if (x == 'r') {
        IMG.src = "imgs/bigArrowR.png";
    } else {
        IMG.src = "imgs/bigArrowR2.png";
    }
}


function redArrowR(x,imgid) {
    IMG = document.getElementById(imgid);
    if (x == 'r') {
        IMG.src = "imgs/arrowR-roll.png";
    } else {
        IMG.src = "imgs/arrowR.png";
    }
}

function redArrowL(x,imgid) {
    IMG = document.getElementById(imgid);
    if (x == 'r') {
        IMG.src = "imgs/arrowL-roll.png";
    } else {
        IMG.src = "imgs/arrowL.png";
    }
}





// -----------------------------------------------------------------------------




function GetXmlHttpObject() {
    var objXMLHttp=null
    if (window.XMLHttpRequest) {
        objXMLHttp=new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}  


function preloadImages(a,b) {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="images.html";
    url=url+"?a="+a+"&b="+b+"&qid="+Math.random();
    
    xmlHttp.onreadystatechange=stateChangedpreloadImages
    
    xmlHttp.open("http://www.americancraftmag.com/OctNov2007/GET",url,true)
    xmlHttp.send(null)
}

function stateChangedpreloadImages() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        document.getElementById('loadextraimages').innerHTML = xmlHttp.responseText;
    }
}





// -----------------------------------------------------------------------------







function editorsLet() {
    if (document.getElementById('editorsLeter').style.display == 'block') {
        document.getElementById('editorsLeter').style.display = 'none';
    } else {
        document.getElementById('editorsLeter').style.display = 'block';
    }
}

function articleOne() {
    if (document.getElementById('article1').style.display == 'block') {
        document.getElementById('article1').style.display = 'none';
    } else {
        document.getElementById('article1').style.display = 'block';
    }
}

function articleTwo() {
    if (document.getElementById('article2').style.display == 'block') {
        document.getElementById('article2').style.display = 'none';
    } else {
        document.getElementById('article2').style.display = 'block';
    }
}

function contactInfoT() {
    if (document.getElementById('contactInfo').style.display == 'block') {
        document.getElementById('contactInfo').style.display = 'none';
    } else {
        document.getElementById('contactInfo').style.display = 'block';
    }
}

function zoomtoggle() {
    if (document.getElementById('zoom').style.display == 'block') {
        document.getElementById('zoom').style.display = 'none';
    } else {
        document.getElementById('zoom').style.display = 'block';
    }
}
  

User is offlineProfile CardPM
Go to the top of the page
+Quote Post


someone1
post 28 Apr, 2008 - 12:19 PM
Post #2


New D.I.C Head

*
Joined: 28 Apr, 2008
Posts: 6

take a look at: http://code.google.com/p/swfobject/

Set the function to overwrite a DIV tag where u want ur swf object placed, then if you want to show the JPG image if flash in unavailable, have the JPG image in the div tag already so it will display if the user doesn't have flash or javascript (assign a minimum flash version the user must have in the javascript function to make sure it only writes in the div tag if the user has that version of flash)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:12AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month