|
|
Subject:
Making swf load last on a web page
Category: Computers > Programming Asked by: andyb-ga List Price: $10.00 |
Posted:
17 Jun 2002 08:03 PDT
Expires: 24 Jun 2002 08:03 PDT Question ID: 27907 |
I have got a web page (www.rdfinternational.com/default3.asp) which has got lots of gifs and a piece of flash. I want to set it up so the flash doesn't download until all the gifs are loaded (At the moment the flash movie and the gifs download simultaneously, meaning that it takes a long time for the page to look OK on a modem). I think this can be done in Javascript using 'onLoad', but I don't understand enough about Javascript to make this work. What is the code I need to write to make this happen? |
|
Subject:
Re: Making swf load last on a web page
Answered By: xemion-ga on 17 Jun 2002 11:53 PDT Rated: |
Ok, this is pretty complicated but I'm going to try to explain it as simple as I can... This works using Javascript and the onLoad event, as you said. It's a little more complicated because you have to modify the Flash movie as well. I'll explain how it works as I go along. In your HTML, your body tag looks like this: <BODY onLoad="MM_preloadImages('images/nav01ov.gif','images/nav02ov.gif','images/nav03ov.gif','images/nav04ov.gif','images/nav05ov.gif','images/nav06ov.gif','images/nav07ov.gif','images/nav08ov.gif','images/nav09ov.gif','images/rgtmoreov.gif');" LEFTMARGIN="0" MARGINWIDTH="0" TOPMARGIN="0" MARGINHEIGHT="0" TEXT="#330000" LINK="#ff6600" ALINK="red" VLINK="#666666"> You need to add "window.document.myFlash.SetVariable('loaded', 'true');" to the onload command to make it look like this (fyi, your rollover code generates an error in ns 4.7, you might want to get it looked at): <BODY onLoad="window.document.myFlash.SetVariable('loaded', 'true'); MM_preloadImages('images/nav01ov.gif','images/nav02ov.gif','images/nav03ov.gif','images/nav04ov.gif','images/nav05ov.gif','images/nav06ov.gif','images/nav07ov.gif','images/nav08ov.gif','images/nav09ov.gif','images/rgtmoreov.gif');" LEFTMARGIN="0" MARGINWIDTH="0" TOPMARGIN="0" MARGINHEIGHT="0" TEXT="#330000" LINK="#ff6600" ALINK="red" VLINK="#666666"> Next, you need to modify your Javascript code. Your code currently looks like this: var oeTags = '<OBJECT' + 'WIDTH="400" HEIGHT="250">' + '<PARAM NAME="MOVIE" VALUE="test.swf">' + '<EMBED SRC="test.swf"' + 'WIDTH="400" HEIGHT="250">' + '</EMBED>' + '</OBJECT>'; Make it look like this (just copy and paste): var oeTags = '<OBJECT' + 'WIDTH="400" HEIGHT="250" name="myFlash">' + '<PARAM NAME=movie VALUE="test.swf">' + '<EMBED SRC="test.swf"' + 'WIDTH="400" HEIGHT="250" swliveconnect=true name="myFlash">' + '</EMBED>' + '</OBJECT>'; That's the easy part :-) Now you have to modify your flash movie. If you don't have access to the flash file, you better get it. If not, it's impossible to do what you're asking. If you don't know how to follow the below instructions, you need to hire a good web developer to do it for you. Just give him the instructions and he should know what to do. If not, you need to hire a different developer :-) This is the easiest (and probably only) solution to your problem. At the beginning of your flash movie, you need to add three blank keyframes. In keyframe number one, insert a dynamic textbox with the name "loaded", value "false". In keyframe number two, insert the below action script: if (loaded == "true") { gotoAndPlay (4); } In keyframe number three, insert the below action script: gotoAndPlay(2); Ok, that's it. The onLoad event will send a message (using javascript) to the flash movie saying the loaded variable now equals "true". Meanwhile, the flash movie is running in a loop while it's waiting for the loaded variable to equal true. As soon as javascript tells flash the variable equals true, flash plays the rest of the movie. Until then, flash just displays a blank screen while the images are loaded. Make sense? Well, I hope I've helped you. I know you stated you don't understand Javascript very well, but this is the only solution so I hope you'll be able to figure it out. If it doesn't work for you, or you run across any problems, please don't hesitate to ask for clarification. I've verified it actually works here: http://www.affiliateindex.com/ga/imagesbeforeflash.htm (notice how the images all load before it says "hi!!") Thanks for the question and if you require more information regarding my answer, don't hesitate to ask for clarification. And if you find this answer satisfactory, please feel free to rate it. Thank you! xemion-ga |
andyb-ga
rated this answer:
Thanks. That is brilliant. |
|
Subject:
Re: Making swf load last on a web page
From: mohsen-ga on 17 Jun 2002 12:51 PDT |
I have another idea for you. Browsers usually don't show the contents of an HTML table untill all the obejcts within it have been loaded. So you can put all the objects of your page within an outer table and check if that's okay for you. This solutions is much far simpler but it might be browser-dependent. Another solution is to use html frames or iframes. This way you have to put your flash inside an iframe. At first the iframe's source is some blank page. after the page loads, you change the iframe's source to your flash file using javascript's onload event. more explanation along with an example can be found at: http://javascript.internet.com/navigation/frames-load-order.html in this examle frame1 is loaded AFTER frame2. hope that helps. mohsen-ga |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 17 Jun 2002 13:40 PDT |
Most browsers show the table after the all of HTML CODE is loaded, not images, so it wouldn't help in this situation. Iframes might work, but iframes only work in Internet Explorer if I remember correctly. Frames is a good idea, but it would probably just be easier to use my above solution instead of breaking the page and navigation into a gazilliono little pieces. Good idea though, mohsen. xemion-ga |
Subject:
Re: Making swf load last on a web page
From: blakeyrat_mac-ga on 17 Jun 2002 16:39 PDT |
The original answerer's example doesn't seem to work... the page loads fine, but I never see "hi!!" no matter how long I wait. |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 17 Jun 2002 23:39 PDT |
What browser and version number are you using, blakeyrat_mac? If you're using NS4.7 you will not see the "hi!!!" because there is a Javascript error on the page in code unrelated to my code. Netscape stops running the Javascript when it encounters those errors which is why the "hi!!!" never shows up. Thanks. xemion-ga |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 17 Jun 2002 23:44 PDT |
And in case you were using NS6 or IEMac, this page explains why the solution does not work with those browsers: http://www.macromedia.com/support/flash/ts/documents/mozilla_fscommand.htm It's really not a big deal because of the small percentage of users with these browsers. These browsers may support the code in the future. xemion-ga |
Subject:
Re: Making swf load last on a web page
From: andyb-ga on 18 Jun 2002 08:49 PDT |
I'm just trying to debug the Javascript error in NS4.7. I have just downloaded NS4.79, but I can't find a Javascipt debugger within it (or any way of getting a Javascript error message to display). How do I see Javascript errors in NS4.7? Thanks for any advice. |
Subject:
Re: Making swf load last on a web page
From: andyb-ga on 18 Jun 2002 09:04 PDT |
xemion, Thinking about it, I am not sure your suggestion works, even in theory (I couldn't test it properly because I only have a fast internet connection). Even though the the flash movie doesn't start playing until the page is fully loaded, it is still downloading, because it is called right at the beginning. Do you think that is right? Or am I misunderstanding what is going on? cheers AndyB |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 18 Jun 2002 10:49 PDT |
The debugger in ns4.7 can be found by entering "javascript:" in the address bar after the website fully loads. Look at your status bar. It'll tell you. You're correct. The movie is streaming while the images are loaded. I did this because I didn't think there was any way around it, but I just thought of something: http://www.affiliateindex.com/ga/imagesbeforeflash.htm Create a NEW Flash movie with four keyframes. Insert the first three keyframes like I instructed you before. On the fourth keyframe, add this script: loadMovie("http://www.rdfinternational.com/test.swf", _level0); This way, your movie, test.swf, won't actually load until the images are done. Just the movie with the four keyframes. That movie is so small it won't effect it at all. Also, when you make your movie, take your dynamic variable and move it off the screen or make it white. That way it won't show up. Just to make things easier on you, here's the source code to the script I made: http://www.affiliateindex.com/ga/flashjs.fla Sorry I didn't think of this before :-) Thanks for the rating! xemion-ga |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 18 Jun 2002 12:39 PDT |
Also, I suggest making a new script detection script to detect NS6 and IEMac browsers. Like this: if (flashenabled = true) { if (ns6 or ie mac) { display "test.swf" } else { display "flashjs.swf" //which in turn will display test.swf when the images are loaded } } else { display intro.gif or whatever } Hope this helps! xemion-ga |
Subject:
Re: Making swf load last on a web page
From: blakeyrat_mac-ga on 18 Jun 2002 16:37 PDT |
<<It's really not a big deal because of the small percentage of users with these browsers. These browsers may support the code in the future.>> I *do* happen to be using IE on a Mac, and I know a VERY LARGE proportion of people also do. To simply say, "well, only 15% of the market uses Macs, perhaps 10% MacIE, therefore it is "not a big deal" is horribly, horrible Windows-centric thinking. Part of the entire *point* of the WWW, and of the HTML format is that it can be viewed as easily with *any computer available*, from a telnet terminal to a $25,000 Sun workstation. In any case, there's no need to punish users of MacOS, Linux, FreeBSD, BeOS, etc simply because they don't represent a "big deal" to you when it only takes a tiny bit of effort to support *all* browsers on *all* OSes. (At least, all that support Javascript.) Gruh. Damn Windows users and their closed minds. There are other OSes out there, and a *large* proportion of them are a hell of a lot better than Windows is. |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 18 Jun 2002 16:52 PDT |
If you will note, I did include a script to provide the Flash movie to Mac browsers. They don't get the full surfing experience, but I did not ignore them. I just merely stated the true fact that a very small percentage of surfers use IEMac browsers. Maybe I'm wrong, but I think only 5% of computers are Macs which would mean an even smaller percentage use the IEMac browser. xemion-ga |
Subject:
Re: Making swf load last on a web page
From: xemion-ga on 18 Jun 2002 19:10 PDT |
To back myself up, the Google Zeitgiest states that 4% of it's visitors use the Mac OS. ://www.google.com/press/zeitgeist.html |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |