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

May 16, 2016 pm 04:40 PM

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 src="/static/imghw/default1.png" data-src="http://files.jb51.net/file_images/article/201301/2013010416185572.gif" class="lazy" style="max-width:90%" alt="" style="max-width:90%" border="0"> 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>



Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles