38773

Load a flash after hitting a button

Question:

I am building a website with my school work (dreamfoxgames.com).

If you click on a button called "play" a popup/Modal will come with the game in flash or unity plugin. My problem is that when a visitor loads the page they will automatic load the flash file. This means that the music will start and the page will be slow with loading (all those games).

Is there a way to only load the flash player after somebody hit the play button?

Thanks a lot!

Answer1:

It can also be done using an embed element (no need for 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>

Answer2:

You can use <a href="https://code.google.com/p/swfobject/wiki/documentation" rel="nofollow">swfobject</a> to load swf content in div.

Suppose if you have a div in your html as below

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

To play the swf..

<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>

Recommend

  • Blending languages - Python and Objective-C
  • “start” command in .bat batch file
  • Botframework - resize bot chat in width [duplicate]
  • Can I have the market update an app that was installed from else where?
  • multiplayer game with bluetooth [iphone]
  • Overriding window.location on Webbrowser Control
  • Declaration of does not work with Ionic's ion-nav-view in IBM MobileFirst
  • How to lookup value with multiple criteria in excel 2007 and newer
  • Why are views not counted if you embed a youtube iframe dynamically using jquery?
  • How to get the click event on sIFR embedded tag in IE?
  • Reloading table causes flickering
  • Netezza Incremental load from Sql server using SSIS
  • LNK1104: cannot open file 'kernel32.lib'
  • How to add regEx in angular filter
  • Glassfish - java.lang.NoClassDefFoundError
  • Is looping through all style sheets and classes a good idea in JavaScript?
  • Regex for Specific Tag
  • How can we prepend rows to a react native list-view?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • What's the purpose of QString?
  • C: Incompatible pointer type initializing
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Jackson Parser: ignore deserializing for type mismatch
  • JQuery Internet Explorer and ajaxstop
  • How to attach a node.js readable stream to a Sendgrid email?
  • Asynchronous UI Testing in Xcode With Swift
  • How to delay loading a property with linq to sql external mapping?
  • Cannot connect to cassandra from Spark
  • Hazelcast - OperationTimeoutException
  • Weird JavaScript statement, what does it mean?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • RestKit - RKRequestDelegate does not exist
  • How to include full .NET prerequisite for Wix Burn installer
  • Revoking OAuth Access Token Results in 404 Not Found
  • Django query for large number of relationships
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal