ajoo Posted September 26, 2018 Share Posted September 26, 2018 Hi all ! The following piece of code works fine. <?php $myVar1 = "best1"; $myVar2 = "best2"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>SWFObject 2 dynamic publishing example page</title> <!-- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> --> <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript"> var myVal1 = "<?php echo $myVar1; ?>"; var myVal2 = "<?php echo $myVar2; ?>"; var flashvars = { myVar1: myVal1, myVar2: myVal2 }; swfobject.embedSWF("AS3_swf_php_comm_1.swf", "myswf", "550", "400", "9.0.0", false, flashvars); </script> </head> <body> <div id="myswf"> <h1>Alternative content</h1> <h2> Best </h2> </div> </body> </html> I wish to convert the following bit : <script type="text/javascript"> var myVal1 = "<?php echo $myVar1; ?>"; var myVal2 = "<?php echo $myVar2; ?>"; var flashvars = { myVar1: myVal1, myVar2: myVal2 }; swfobject.embedSWF("AS3_swf_php_comm_1.swf", "myswf", "550", "400", "9.0.0", false, flashvars); </script> into a file jquery file movie.js thereby removing the above inline code. Please can someone help me convert this or convert it for me. Thanks all ! Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/ Share on other sites More sharing options...
requinix Posted September 26, 2018 Share Posted September 26, 2018 What's stopping you from copying and pasting that Javascript code into a file and referencing it with a <script href>? Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561131 Share on other sites More sharing options...
ajoo Posted September 26, 2018 Author Share Posted September 26, 2018 Hi Requinix, Thanks for the reply, May i request you to show me how to do it in the example above. Will be much obliged. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561134 Share on other sites More sharing options...
ajoo Posted September 26, 2018 Author Share Posted September 26, 2018 Hi requinix & all ! Ok so i have tried a couple of things and I feel that the error that occurs is due to the fact that the variables <script type="text/javascript"> var myVal1 = "<?php echo $myVar1; ?>"; var myVal2 = "<?php echo $myVar2; ?>"; . . . myVar1 and myVar2 do not get passed into the external.js, JQuery file, if they are defined as is in the external,js file. So then how do i pass the php variable into the external.js JQuery file? If someone can help me with this, i think i would sort the rest. Thanks all ! Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561135 Share on other sites More sharing options...
Barand Posted September 26, 2018 Share Posted September 26, 2018 Perhaps, in your php, you could put those two values into hidden fields. Then, in your javascript, pick up the values from there. var myVal1 = $("#myvar1").val() 1 Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561136 Share on other sites More sharing options...
ajoo Posted September 26, 2018 Author Share Posted September 26, 2018 Hi Guru Barand !! Thanks for that reply. It works great ! I would have replied earlier but i was busy trying out some other methods for the same purpose. your suggestion is perhaps the simplest. Thanks laods ! Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561142 Share on other sites More sharing options...
kicken Posted September 27, 2018 Share Posted September 27, 2018 Setup your javascript file to read your variables off the script tag. Then set data- attributes for your variables when importing the script. (function(){ var script = document.currentScript; var flashvars = { myVar1: script.dataset.myval1, myVar2: script.dataset.myvar2 }; swfobject.embedSWF("AS3_swf_php_comm_1.swf", "myswf", "550", "400", "9.0.0", false, flashvars); }()); <script type="text/javascript" src="flash.js" data-myvar1="<?=htmlspecialchars($myVar1)?>" data-myvar2="<?=htmlspecialchars($myVar2);?>"></script> Quote Link to comment https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.