Jump to content

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
https://forums.phpfreaks.com/topic/307725-inline-to-filejs/
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
https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561135
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
https://forums.phpfreaks.com/topic/307725-inline-to-filejs/#findComment-1561179
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.