Home > Web Front-end > HTML Tutorial > Flash embedded in html Solution for embedding Flash files in html web page code (Part 1) _HTML/Xhtml_Web page production

Flash embedded in html Solution for embedding Flash files in html web page code (Part 1) _HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:40:34
Original
1561 people have browsed it

It is the custom of the Chinese people to celebrate the New Year before the fifteenth day of the first lunar month. Here I would like to wish your friends in the garden a happy new year.
In the past few days, the company's website homepage needs to be revised. After the company's "staff reduction" at the end of last year, one person has to do the work of multiple people, and suddenly he feels that the burden is heavy. No, this is not something within the scope of my work. Unfortunately, I have been involved in it. Fortunately among the misfortunes, the task assigned to me by BOSS this time is exactly the front-end development task I have always been passionate about. I have been engaged in the development of back-end management programs for the company's website before, mostly processing business logic on the server side. I have never had the opportunity to put my skills into use in front-end development, which I am passionate about. Practice is the best way to test true knowledge. Solving the practical tasks assigned to me is a rare test. I learned a lot of scattered knowledge through books and various materials, but did not get the opportunity to combine them together. Comprehensive test”, haha. There are so many ink stains on the front, which are caused by suppressing them for a long time, haha.

Let me first describe the task requirements: There is a JPG picture composed of five balls on the homepage of the company's website. It is used for navigation. Clicking on the text on each ball will open the corresponding information. On the secondary page, there is an almost identical Flash version corresponding to the image. One of the tasks assigned to me by my boss is: when the client browser has a Flash file player installed, the Flash version of the navigation is displayed, and vice versa, the JPG image navigation is displayed. After getting the task, think about it for a moment. As a front-end development, of course you have to consider browser compatibility issues. The best way to bridge the gap between browsers is to use one or more mature JavaScript frameworks. Fortunately, there happens to be one A very mature and sophisticated JS framework exists, named: SWFObject.js.

The first time I came into contact with SWFObject.js was its V1.5, and this time I used V2.1 to solve the problem. There are still some differences in the use of the two. Overall, I feel that V2.1 is a big leap forward compared to V1.5. V2.1 is more in line with the object-oriented JavaScript programming style in terms of the source code of the framework and the usage process.

I will take you to experience this "tortuous" journey from the perspective of a researcher who has just explored JavaScript. Whether you are a novice like me, or you are already proficient in writing various JS As a veteran of coding, please be merciful and hope that everyone can point out the short-sightedness in my thinking and the errors in my writing in a civilized manner.

The following code is an example of usage that I adapted from a documentation of SWFObject V1.5 (if you want to learn more about V1.5, please click this link):

Copy code
The code is as follows:


DEMO</title> ; <br /><head> <br><script type="text/javascript" src="swfobject_source.js"></script> <br><script type="text/javascript"> <br>var so = new SWFObject("http://www.pec365.com/Flash/20071113.swf", "mymovie", "304", "367", "7", "#FFFFFF"); <br>so.write("flashcontent"); <br></script> <br></head> <br><body> <br><form id="Form1"> <br> <div id="flashcontent"> <br><a href="http://www.adobe.com/go/getflashplayer"> <br><img src="http://www. adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" /> <br></a> <br></div> <br>< ;/form> <br></body> <br></html> <br> </div> <br>If you want to briefly understand the meaning of each parameter in SWFObject(), please refer to the documentation, which I won’t repeat here. <br>I strongly recommend that you copy the code in "V1.5 Usage Example" into Notepad, and click SWFObject V1.5 to download the source file of the required V1.5 framework. After decompressing, find swfobject_source.js (uncompressed version, the file name of the compressed version is swfobject.js) file, rename the notepad file to demo.html and place it in the same folder as the swfobject_source.js file. Then please install it in IE6/IE7 and fox respectively. Run it in any browser such as , opera, safari, navigator, chrome, etc. and see what the result is. <br>If you follow my suggestions, you should find that this picture <img style="max-width:90%" alt="" style="max-width:90%" border="0" src="http://files.jb51.net/file_images/article/201301/2013010416185572.gif"> is displayed on the page instead of a Flash file. Why is this? If you happen to have the IE series installed on your PC, please follow the steps below: Click the IE browser icon, find the "Tools" menu on the toolbar, select "Internet Options", and click "Advanced" in the window that opens. , find the "Disable Script Debugging (Internet Explorer)" option, uncheck the box in front of it, and click "OK". After completing the above operations, please browse the demo.html page again. Will you find an error prompt box popping up with the following error message: "A runtime error has occurred. Do you need to debug? Line: 117 Error: 'null' is Empty or not an object. ” <br><br>If you happen to be using the VS 2003/2005/2008 series of IDEs for development, then I don’t need to teach you how to debug JavaScript code. You can var so = above... Open a debugger, and then debug and trace it. Keep pressing F11 until you trace the inside of the swfobject_source.js file through the so.write() method. You will find that the actual parameter "flashcontent" passed to so.write(elementId) is in the document. The value of .getElementById("flashcontent") is always null. Why is this? Found the problem? <br><br>Haha, if you are still a newbie who doesn’t know much about JavaScript, you will be as confused as I was at that time. After many times of debugging and modifying the code, I firmly believe that what I wrote There is no error in the JS code itself. Is there a problem with the externally loaded swfobject_source.js file? If there is a problem, where is the problem? At that time, I was looking for a solution to the error, and I modified the above code into the following example: <br><br><div class="msgheader"> <div class="right"><span style="CURSOR: pointer" onclick="copycode(getid('phpcode34'));"><u>Copy code</u></span></div>Code As follows: </div> <div class="msgborder" id="phpcode34"> <br><html> <br><title>DEMO





< /form>


If you execute the above code, you will find that this picture is still displayed on the page, and a warning box containing "The element does not exist" will pop up. It seems that the problem is not caused by external loading. swfobject_source.js file.

If you see this, you will definitely experience my annoyance at that time. After taking a short rest, I cleared my mind and looked back, only to find that the essence of the problem lies in "HTML DOM loading". In a page, JS scripts in the head of the page (that is, between ) and JS files loaded from external files will be executed before the HTML DOM is actually constructed. Therefore, the scripts executed in these two places cannot access the DOM that does not yet exist. You should know the real reason, which is that during the execution of the JS code in Example 1.1, the
...
that has not yet been constructed is accessed.

Okay, after seeing this, there is one last step that you need to do yourself, which is to simply modify the above code and adopt an inelegant method to solve it
About "HTML DOM" "Loading" problem, which method is it? I think you may have guessed it. Yes, it is exactly the following method:

Copy code
The code is as follows:


DEMO

_fcksavedurl=""swfobject_source.js">"

< body>



Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template