Jump to content

inline to file.js


ajoo

Recommended Posts

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 !

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.