Solved

call variable in ,js to swf file

Posted on 2007-12-03
6
580 Views
Last Modified: 2008-02-01
I need to pass a variable number from the random number generator in the <HEAD>

to the "var so = new SWFObject" statement in the body.

Note that '+gifnum+'.swf does not call any of my swf files, such as 1.swf, 2.swf, etc.

But that's what I want to have happen.

However, the "document.write" is calling my gif files (1.gif, 2.gif, etc.) just fine.



<SCRIPT LANGUAGE="JavaScript">
function setRandomNumber(){
gifnum = Math.floor(Math.random() * 6) + 1;}
setRandomNumber()
</SCRIPT>
</head>


<body>
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("images/'+gifnum+'.swf", "sotester", "910", "250", "9", "#FF6600");
so.write("flashcontent");
</script><br>
      
      
<script language="JavaScript">
document.write('<img width="200" height="191" src="http://videojobshop.com/images/' + gifnum + '.gif"><br>');
</script>
      
0
Comment
Question by:alanjacobson
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20401307


<SCRIPT LANGUAGE="JavaScript">
var gifnum=1; // default
function setRandomNumber(){
  gifnum = Math.floor(Math.random() * 6) + 1;
}
setRandomNumber()
</SCRIPT>
</head>
 
 
<body>
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("images/'+gifnum+'.swf", "sotester", "910", "250", "9", "#FF6600");
so.write("flashcontent");
</script><br>
      
      
<script language="JavaScript">
document.write('<img width="200" height="191" src="http://videojobshop.com/images/' + gifnum + '.gif"><br>');
</script>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20401314
I prefer
<SCRIPT LANGUAGE="JavaScript">
function setRandomNumber(){
  return Math.floor(Math.random() * 6) + 1; 
}
</SCRIPT>
</head>
  
<body>
<div id="flashcontent"></div>
<script type="text/javascript">
var so = new SWFObject("images/'+gifnum+'.swf", "sotester", "910", "250", "9", "#FF6600");
so.write("flashcontent");
</script><br>
      
      
<script language="JavaScript">
document.write('<img width="200" height="191" src="http://videojobshop.com/images/' + setRandomNumber() + '.gif"><br>');
</script>

Open in new window

0
 
LVL 5

Expert Comment

by:TheGD
ID: 20403663
Your problem is you have not properly used the string quotes

Replace the esixting statement with the following one and you would have it (Copy Paste from here):

var so = new SWFObject('images/'+gifnum+'.swf', "sotester", "910", "250", "9", "#FF6600");

Thanks.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20403899
Ahh, Missed that...

I see that my suggestion then would not work well if you want to match the random swf with the image
0
 

Author Comment

by:alanjacobson
ID: 20404781
I got this from Sinoj Sebastian, which solved my problem


var so = new SWFObject("images/"+gifnum+".swf", "sotester", "910", "250", "9", "#FF6600");

For a string you can use "single quote" or "double quote". But you cannot mix it together. If you have a "single quote" inside "double quote",  "single quote" will be considered as the part of the string.

0
 
LVL 5

Accepted Solution

by:
TheGD earned 125 total points
ID: 20413677
O Yes, I have already suggested that.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert from xls to xlsx using java 7 39
Checking data with javascript 3 19
CSS: Making Pure CSS read more boxes thinner 5 31
Javascript Form Change 5 18
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question