Activate a flash by pressing a button

I'm currently working on my school project, a website called dreamfoxgames.com.

When you click on the "play" button, a popup/modal will appear with either a flash or unity plugin game. My concern is that when a visitor lands on the page, the flash file automatically loads, causing music to start playing and slowing down the loading of the page with all those games.

Is there a way to ensure that the flash player only loads after someone clicks the play button?

Thank you!

Answer №1

Another method involves utilizing an embed element within the HTML code, eliminating the necessity for an external API:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
    var flashEmbed = null;
    function startFlash() {
    if(flashEmbed != null) {
        document.getElementById("flashContainer").removeChild(flashEmbed);
    }
    flashEmbed = document.createElement("embed");
    document.getElementById("flashContainer").appendChild(flashEmbed);
    flashEmbed.src="Flashfile.swf";
    flashEmbed.type="application/x-shockwave-flash";
    }
</script>
</head>
<body>
<button onclick="startFlash()">start flash</button>
<div id="flashContainer"></div>
</body>
</html>

Answer №2

If you want to load swf content within a div, you can utilize swfobject for that purpose.

Imagine having a div in your HTML like this:

<!DOCTYPE html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 
    <script>
</head> 
<body>
      <div id="myContent">
        swf content will go here
      </div>
     <button onclick="playSwf()">Click to play swf</button>
</body>
</html>

To play the swf file...

 <script type="text/javascript">
    function playSwf()
    {
       //Syntax  
       //swfobject.embedSWF(swfUrl, id, width, height, version,
      //                    expressInstallSwfurl, flashvars, params,
     //                     attributes, callbackFn)

         //optional parameters omitted
         swfobject.embedSWF("test.swf", "myContent", "400", "400","10"); 

    }
    </script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Text input in Bootstrap not reaching full width

Trying to achieve a Bootstrap textfield embedded in a panel that spans 100% of the remaining space-width within the panel. However, this is the result obtained: The blue border represents the edge of the panel. Below is the code being used: <div clas ...

Issue TS7053 occurs when trying to access any index of the target of a React.FormEvent<HTMLFormElement>

I've been working on adapting this tutorial to React and TypeScript. Here is the code snippet I have implemented for handling the onSubmit event: const handleSignUp = (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); ...

AngularJS and KendoUI integration experiencing delays during script evaluation

At the moment, I am conducting performance measurements and analysis on our AngularJS-KendoUI application in an effort to identify any bottlenecks. Following a helpful article and an informative presentation, I am using Chrome DevTools timeline tab to anal ...

Issue with IE11 when using Bootstrap 4 and Flexbox

In my design, I have two columns that need to have equal heights when displayed next to each other on a large screen. However, on mobile devices, they should stack on top of each other. I am currently using the old BS grid for this layout. The content wit ...

Maintain the original alignment of table cells <td> even when the <tbody> element is set to display:block

I've been working on creating a theme for SMF, but I'm encountering some challenges with the tables. Here's an example of my HTML code: <div id="wrapper"> <table class="table_list"> <tbody class="header"> ...

JavaScript escape sequences are used to represent characters that are

Is there a way to pass a variable to another function in this scenario? I am inserting a textarea using JavaScript with single quotes, but when the function myFunction(abc123) is called, it appears like this, whereas it should look like myFunction('ab ...

Using AngularJs to have two ui-views on a single page

As a beginner in AngularJs, I encountered an issue with having two ui-views on the same page. When I click a button to show the view for goals, both the form for goals appear in ui-view 1 and ui-view 2 simultaneously. I have been working with states but I ...

Buttons for displaying and concealing content are unresponsive

After spending over 6 hours trying to fix this code and searching online, I am completely frustrated. My goal is to hide the login table and its associated background image (#lg #ck) and instead, place a button on top of where the login table is. When thi ...

Running zgrep using node.js

I'm looking to incorporate the zgrep command into my node.js app. Currently, I have successfully integrated the grep command as shown below: const grep = require('grep1'); grep(['greptext', './logs/file], function(err, stdou ...

Expanding the height of div elements while dynamically including content

Currently, my web application is designed to dynamically add content using ajax and then slide down. It typically includes two divs on either side with a height of 100% and a repeated image acting as a border. However, when new content is added, the bord ...

Is there a way to update my Google Maps .html file on my android phone to pan to my current location?

An objective is to create a local .html file on an android device that can be accessed through a standard web browser, allowing users to pan to their current location on Google Maps. Presently, the panning feature works on the Mi browser on android devices ...

Get the package from a Lerna-managed monorepository using a git URL

Currently working on a project using yarn. The project has a dependency that is part of a larger monorepo managed by lerna. Despite the subpackage being updated, it has not been published yet and I require access to that unreleased code. Is there a method ...

Refreshing the page using location.reload triggers a reload of various elements

I am currently working on a website that supports multiple languages and utilizes a cookie named nav_lang to determine the user's preferred language for navigation. Whenever a user selects a new language, the cookie is updated accordingly and the page ...

What is the best way to incorporate tailored validation into reactive forms in Angular?

I'm facing an issue with my form where I'm trying to display a specific error message based on certain conditions. Currently, my form is functioning but it's throwing a type error stating "undefined is not an object". I'm struggling to ...

Can the tooltip on c3 charts be modified dynamically?

Creating a c3 chart involves defining various properties, including a tooltip. Here is an example: generateData = () => { const x = randomNR(0, 100); const y = randomNR(0, 100); const together = x + y; return { data: { columns: [ ...

Occasionally encountering the error message "Cannot find the length of undefined"

Recently, I developed a tool that required me to create a series of dropdown menus for selecting a profile/view id from Google Analytics. This process involved dynamically populating the next menu based on the user's selection in the previous one. Alt ...

What is the most effective way to extract information from a .txt file and showcase a random line of it using HTML?

As a newbie in HTML, my knowledge is limited to finding a solution in C#. I am attempting to extract each line from a .txt file so that I can randomly display them when a button is clicked. Instead of using a typical submit button, I plan to create a custo ...

Obtain an Instagram access token with the help of Node.js

I've been attempting to acquire an access token from Instagram without utilizing a browser request, using the instagram-node module. However, I haven't been successful in receiving the access token. Can anyone provide me with a solution that does ...

Suggestions on how to refactor redundant code in various peer AngularJS controllers for handling $intervals

In my compact single-page application, I have implemented multiple tabs to display operational status information for different applications. Each tab is associated with a controller that creates $interval objects to make AJAX calls to fetch status data fr ...

Processing AJAX request without reloading the page using PHP

I need assistance with creating an image cropping tool that allows users to upload a picture, crop it, and display it on the page as an image.jpg rather than as base 64 (data:image). I have tried using HTML and JavaScript but it seems impossible, so now I ...