Not signed in (Sign In)

Vanilla 1.0.3 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorgayleamy
    • CommentTimeSep 28th 2007
     
    I've been trying to use your tutorial "AJAX and SWFobject" and I've been having no luck getting the .swf to appear, but am getting a big white box with a smaller black box inside of it... This is progress, actually, because I wasn't getting anything before. I'm unfortunately very new to both AJAX and Flash, and so could be doing something very obviously wrong; would you be able to look at it and see if you can tell what I'm doing incorrectly?

    The page is here: http://www.gayleamy.com/loren

    The .xml file I created is here:
    http://www.essents.net/gayleamy/loren/videos/BBC_VOMT.xml

    And the link that's supposed to be triggering this all is under
    "Videos;" "BBC VOMT 2002."

    This might have to do with a conflict with one of the other scripts running (jquery and lightbox, along with the ajax) or is due to an error I've made in the .xml. (I've got it stripped-down to practically nothing at this point, just testing what could be wrong...) I'm just not sure how to proceed from here.

    Any help you can give will be greatly appreciated!
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007 edited
     
    SWFObject instantiates fine. i don't have a quickie answer for you... sorry. :)

    in this type of scenario, path issues often pop up. this happens most frequently with 'player' SWFs like the one you're trying to use (a video player).

    the player SWF needs to load the target file (FLV in this case); when the 'player' SWF looks for the FLV, it checks the path you gave it relative to the 'player' SWF, not relative to the HTML page the player SWF was embedded onto.

    to eliminate path issues, try using the SWF's absolute URL in your XML file and the absolute URL for your FLV in your 'player' SWF.

    you can also try embedding the SWF without using the XML file. this will help isolate the problem (removes xmlhttprequest from the equation). set the onclick for the 'video' link to load the swf directly:



    <li><a href="videos/BBC_VOMT.swf"
    onclick="loadSWF(this.href); return false;">BBC VOMT 2002</a></li>

    function loadSWF(url){
    var so = new SWFObject(url, "flashVarsExample", "550", "400", "8", "#FFFFFF");
    so.write("contentinner");
    }



    frankly, i'm not sure why you're using xmlhttprequest in this instance... from a usability perspective, if the visitor doesn't have JavaScript enabled, the xmlhttprequest method denies them all access to the SWF. if you use the method i just described, if the user had JS disabled they will still be able to view your SWF by clicking the hyperlink (assuming they have Flash installed).

    - philip

    PS - extra observations:
    you have a typo. div id-"right" should be div id="right"

    when declaring a SWFObject instance, even if you want it to be transparent, you should specify a background color. i'm not 100% sure if it's required, but i think it helps maintain consistent coding practices. besides, if you use wmode=transparent, the bg color you specify will be ignored, anyway. doesn't hurt. :)
    • CommentAuthorgayleamy
    • CommentTimeSep 29th 2007
     
    Thanks for your reply, Philip. Unfortunately, I know just enough about all of this to have gotten myself into this trouble, and I really don't want to waste your time... I don't understand all you said; I'll try to answer some questions, and then possibly you can help me to figure it out.

    In reference to the path issues, all of the files are in the same folder; both .swf and .fla (and .xml) in "videos." I don't understand "using the SWF's absolute URL in your XML file and the absolute URL for your FLV in your 'player' SWF..." Do you mean a setting needs to be changed in the SWF file? If so, I don't know how that's accomplished - all of the settings were created by Flash 8 when I created the file(s), and the locations haven't changed; it was all saved to "videos."

    Embedding the SWF without the XML works, but opens the player standing alone on a new page, which doesn't suit my needs. The reason I'm using ajax for the page to begin with is because I need the user to be able to browse the site without interrupting the mp3 player embedded in the top page.

    I need to have the SWF appear in the content div upon clicking the link in the navigation. Certainly, they will need to pause the music player in order to watch the video, but I want them to have the option of just pausing it, and resuming it... browsing back to the page from the SWF would refresh the entire site and restart the player. What you achieve in the "Ajax + SWFObject" tutorial/demo is exactly what I need to have happen; the player appear (without autostart) in the content div. I'm confused as to why you'd question me using xmlhttprequest, as I thought that was the purpose of the tutorial...(?)

    Since I'm using Ajax to run the site entirely, I've determined that the percentage of people who disable javascript is negligible; especially with it being a site with the Entertainment Industry as it's target audience. I figure the typical user (casting agents, press) is going to be accustomed to dynamic sites...

    Finally:

    1) Thanks for catching the typo!

    2) (Ahem...) How do I specify the background color?

    If I haven't frustrated you entirely, I'd be grateful for any further guidance you can give; specifically what coding I need in the XML to make this work, provided my other coding is correct(?)

    Thank you,
    Gayle
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007 edited
     
    hi gayle

    usng the example in my last post won't cause the SWF to load in a new page; the SWF will load into the "contentinner" target DIV. the SWF would load in a new page ONLY if the user has JavaScript disabled (if they have JS disabled, 'onclick' will not work). this is a best practice, as it makes the site more accessible, yet still provides the whiz-bang experience for users who have JS enabled.

    (as an aside, if you want to read more about this line of thinking, i highly recommend Jeremy Keith's two books: DOM Scripting and Bulletproof Ajax. they're easy to read and a great primer for less experienced developers.)

    the ajax example i wrote on my site doesn't promote an XML file containing the SWF parameters as 'the answer'... it's much easier to specify SWFObject parameters directly in JavaScript and avoid xmlhttprequest entirely. my example was just illustrating a way of getting ajax and SWFObject to play nice together since some people had been posting questions about the topic on this forum.

    having seen what you're doing with this site, i don't think you need to use xmlhttprequest for loading your SWFs. perhaps it's needed for other content such as HTML pages, but not SWFs.

    regarding the 'path' issue: what URL did you use for the FLV when you made your SWF? if you used something like "videos/BBC_VOMT.flv" instead of "BBC_VOMT.flv", your video will NOT load correctly when loaded into the HTML file.

    assuming this is the file structure of your site:

    loren/index.html
    loren/videos/BBC_VOMT.flv
    loren/videos/BBC_VOMT.swf
    loren/videos/BBC_VOMT.xml

    the FLV should be specified relative to the SWF, not relative to the HTML file. so the FLV's path should be specified in the SWF as BBC_VOMT.flv, not videos/BBC_VOMT.flv.

    what i was suggesting earlier is simply to use absolute URLs in an effort to eliminate any confusion about the file paths. if you use http://www.gayleamy.com/loren/BBC_VOMT.swf and http://www.gayleamy.com/loren/BBC_VOMT.flv, you'll be certain the file paths you specified aren't the cause of your problems.

    - philip
    • CommentAuthorgayleamy
    • CommentTimeSep 29th 2007 edited
     
    God, I'm feeling stupid, but here's the information I can give:

    I've checked the file in Flash, and the content path is "BBC_VOMT.flv" in the FLV and the SWF (If that makes sense; wherever it shows the path in either file, it says: "BBC_VOMT.flv.")

    The way I've been testing it locally (and I've uploaded the updated files to the host at this point) is with the following coding on the top page (stripped of all the other stuff):

    <html>
    <head>
    <script type="text/javascript" src="javascript/swfobject.js"></script>

    <script type="text/javascript">

    function loadSWF(url){
    var so = new SWFObject(videos/BBC_VOMT.swf, "flashVarsExample", "550", "400", "8", "#000000");
    so.write("contentinner");
    }

    </script>

    </head>

    <body>

    <li><a href="videos/BBC_VOMT.swf" onclick="loadSWF(this.href); return false;">Voice of Musical Theatre</a></li>

    <div id="contentinner">

    </div>
    </body>
    </html>

    The way the files are arranged locally are:
    websites/lorengeeting/index.html
    websites/lorengeeting/videos/BBC_VOMT.swf, BBC_VOMT.flv...

    On the host, for testing, it's actually: http://www.essents.net/gayleamy/loren/index.html and http://www.essents.net/gayleamy/loren/videos/BBC_VOMT.swf

    When I put just "BBC_VOMT.swf" in the link (locally), I get the "Page not found" message." When I specify "videos/BBC_VOMT.swf" as above, it opens the player in a new page, against a white background. My coding is obviously incorrect, if it's supposed to be opening in the content div, but I don't know WHAT to put WHERE at this point...

    I went searching for an answer when finding I couldn't simply embed the player into an html and then call it with ajax... And found your tutorial; thinking that it meant that I couldn't do this without the XML file method...

    I'm so frustrated... Thanks for your help!

    Gayle
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007
     
    here's a working example of using an onclick event to load a SWF into a specified DIV: http://www.pipwerks.com/lab/swfobject/load-onclick/index.html

    you should be able to modify this example to suit your needs. :)

    - philip
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007 edited
     
    PS - try it with JavaScript disabled and you'll see what i mean about accessibility
    • CommentAuthorgayleamy
    • CommentTimeSep 29th 2007
     
    Okay... That was very, very helpful! Thank you, and bless you and all you come into contact with on a daily basis. ;)

    Now, however (sorry, there IS a "however"), the file is showing up without the skin; ie: the player controls. I'm sure there's probably a flashvars part of the coding that I need, but I'm still a little lost at this point...

    Guidance? (Thanks again for your help!!!)

    You can see it at: http://www.gayleamy.com/loren under "videos" and the first link.

    Gayle
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007 edited
     
    i know this is off the SWFObject topic (i try to keep people on-topic in here!), but since i believe in helping people make their sites as accessible as possible, i figured i should throw this out there for you:

    if you make a slight change to your other 'ajax' links, you can make your site much more accessible to browsers with JS disabled, and your site will work the same if JS is enabled. this is very easy to do:

    current code:

    <li>
    <a href="javascript:ajaxpage('videos/video2.html', 'contentinner');">"If I Sing" 2006</a>
    </li>


    should be changed to:

    <li>
    <a href="videos/video2.html"
    onclick="ajaxpage(this.href, 'contentinner'); return false;">"If I Sing" 2006</a>
    </li>


    (i have line breaks in the code to make it more readable in this forum... you can write it all on one line in the real world)

    what i've basically done is give the link a real, functioning URL. but to keep people from actually following the link (loading the link in a new page), we've added an onclick function followed by a "return false;" statement. the onclick function is the same "ajaxpage" function you were already using, and we didn't need to modify any of your other code to make things more accessible. easy, huh? :)

    accessibility also has other benefits, such as being more search-engine friendly. it's a good thing.

    i'll take a look at your skinning issue in a few minutes.
    - philip
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007
     
    your FLV player isn't showing the player skin because the skin can't be found. the player skin is contained in an external file named "SteelExternalPlaySeekMute.swf"; somehow the player SWF can't locate the 'steel' SWF. this gets back to file paths... if you can specify the absolute path for the 'steel' SWF in your player SWF, everything should be fine.

    you could also ditch the FLV player you're using in favor of something else. the free JW FLV Player is really popular and easy to implement. it works really well with SWFObject and javascript.

    http://www.jeroenwijering.com/?item=JW_FLV_Player
    • CommentAuthorgayleamy
    • CommentTimeSep 29th 2007
     
    Okay... That there is a file path issue with the skin makes no sense, as the files were all created at the same time, and saved by Flash to the same folder...

    But I'm over it, if I can use Jeroen's player instead; I'm a big fan of his Mp3 player and have used it repeatedly...

    So. You can get rid of me for good if you just help me to understand HOW to do that... Working with the code given in the example on his page involving SWFObject:

    <script type="text/javascript">
    var so = new SWFObject('mp3player.swf', 'mpl','300','250','7');
    so.addParam('allowfullscreen','true');
    so.addVariable('file','song.mp3');
    so.addVariable('autostart','true');
    so.write('flashbanner');
    </script>

    Would I then just append the script I already have (below) somehow?

    <script type="text/javascript">

    function loadSWF(url){

    var so = new SWFObject(url, 'BBC_VOMT', '450', '300', '8', '#000000');
    so.write("contentinner");

    }

    </script>

    Would it work together from the same onclick event?

    Again, thanks...

    Gayle

    P.S. I'll use the code for my ajax links you suggested - I am very interested in accessibility, as well as optimization for search engines.
    • CommentAuthorphilip
    • CommentTimeSep 29th 2007 edited
     
    sorry, i neglected to mention that if you use the JW FLV player, there's a wee bit of trickiness in setting up the URL. BUT... it isn't a huge deal, so i wouldn't sweat it. i'll try and explain it.

    here's a working example you can follow:
    http://www.pipwerks.com/lab/swfobject/load-onclick/jw-FLV2.html

    (BTW, you need the FLV player, which is a different SWF than the MP3 player)

    first, i renamed the "loadSWF" function to "playFLV" since that's specifically what we're trying to do. we still pass the SWF's URL as a parameter.


    function playFLV(playerURL){
    var w = Number(playerURL.split("width=")[1].split("&")[0]);
    var h = Number(playerURL.split("height=")[1].split("&")[0]);

    var so = new SWFObject(playerURL, 'flvPlayer', w, h, '7', '#000000');
    so.write("flashcontent");
    }


    you probably noticed the new "var w =" and "var h =" stuff. i'll explain them in a moment.

    also note that i didn't set up any of the optional JW settings, such as autoplay or default image. you can add those later.

    next up we have the rebuilt link for users to click.


    <p>
    <a href="/lab/_common/flvplayer.swf?height=400&amp;width=550&amp;file=/lab/swfobject/load-onclick/video.flv"
    onclick="playFLV(this.href); return false;">
    Click here to load the SWF!</a>
    </p>


    the onclick attribute is pretty straightforward, almost exactly like your previous function. the function "playFLV" is still passing the href of the link. the big change is what's contained in the href.

    the href was changed to this long-winded URL:

    /lab/_common/flvplayer.swf?height=400&amp;width=550&amp;file=/lab/swfobject/load-onclick/video.flv


    why? because unlike your previous FLV player, the JW player doesn't have the FLV file's location hard-coded into the player. with the old SWF, the FLV location was hard-coded into the SWF, so we could just link to the SWF and it would load the external FLV with no extra configuration work. with the JW FLV player, we have to link to the JW SWF, then pass the FLV location (and other JW config settings) to the SWF using a querystring (?height=400...).

    it's a little extra work to set up the querystring, but doing it this way ensures browsers with javascript disabled will still be able to watch the video!

    the cool thing is that we can now automate the 'playFLV' function to grab the info from the querystring and automatically insert the SWF size into the SWFObject declaration for us. (the "var w =" and "var h =" tidbits.) this means you can use different sized FLV files and not have to recode your SWFObject declaration each time you load a new FLV.

    the normal SWFObject implementation of the JW player (the one shown in the JW FLV player's documentation) includes the line

    addVariable("file", "video.flv");


    what we're doing in this instance is using the querystring -- NOT SWFObject's addVariable method -- to pass the "file" data for us, which means we don't need to set up any addVariable lines in SWFObject. it simplifies the process for us.

    please note that i entered both the FLV URL and the SWF URL as site-relative links, which are shorter than absolute URLs but more reliable than document-relative URLs. this is an important point because the file to be played has to be listed relative to the flvPlayer.swf file, NOT the HTML file it loads into. using site-relative links means i don't have to worry about it. you could also use absolute URLs.

    also note that you should use the entity &amp; instead of the character & in querystrings to avoid issues with XHTML doctypes.

    hope this makes sense... :)
    - philip
    • CommentAuthorgayleamy
    • CommentTimeSep 30th 2007
     
    Oh Philip... I may name my first-born after you.

    I have to admit that the above scared me a bit at first, but it worked the first time I tried it! Thank you so much for all of your help - you're an absolute godsend.

    By the way, you probably want to change the title of this thread, since it didn't end up really having to do with the tutorial I referenced. It's been such a fabulous step-by-step instruction, that I would want other people to benefit, and they'll need to know where to find it!

    THANK YOU!
    Gayle
    • CommentAuthorzhangsisi
    • CommentTimeOct 1st 2007
     
    you hello I want to men friend ,trcut me , you can see me
    www.ConnectAsia.info/en/lang104082about_lili11
    thank you
    • CommentAuthorakbar
    • CommentTimeDec 13th 2007
     
    Ok I have been trying all day to get this work but no luck so far, first of all when index.html opens when I click on the link for xml it does nothing (nothing happens) and I am going crazy with this. this is the first issue, second would be how can I change the script to make xml load automatically? any idea would be appreciated it:)
    • CommentAuthorrostislav
    • CommentTimeDec 17th 2007
     
    Check http://www.asual.com/swfaddress/samples/coherence/#/portfolio/1/

    It loads http://www.asual.com/swfaddress/samples/coherence/datasource/portfolio1.xml via XHR and uses the following code to embed the response:

    function updateContent(html) {
    var content = document.getElementById('content');
    content.innerHTML = html;
    while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
    block = html.substr(0, html.indexOf(RegExp.$1));
    html = html.substring(block.length + RegExp.$1.length);
    eval(block);
    }
    }
    updateContent(xhr.responseText);