Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Syntax Help: getURL ("javascript:myfunction(var1, var2); 1

Status
Not open for further replies.

teekay

IS-IT--Management
Feb 14, 2002
6
US
Hi,

I have a simple yet perplexing question.

I am writting an action script getURL to pass a variable to an external Javascript function. Here is the simple version:
----- fuction -----
function myfunction(var1, var2)
{
document.write('This is var1' +var1 +'this is var2' +var2)
}

----- in Flash file ----
var1 = "hello"
var2 = "world"
getURL ("javascript:myfunction(var1, var2)");


I tried various syntax, but it doesn't want to work. If I hardcode string values, it is passed, but I can't get the variable to pass. And I am sure that the variable contains teh value.

I tried this syntax, but didn't work
getURL ("javascript:myfunction('" +var1 +',' +var2 +'");"

Can anyone show me a working syntax to pass these varialbes?

Any help or suggestion would greatly be apprciated.

Thank you for your time :)

teekay
 
Well this does work with your function as scripted...

on (press) {
getURL ("javascript:myfunction('Hello ', 'World!')");
}

Regards,
new.gif
 
Thank you for your reply.

I know if I put the values in.. it does work. I want to know the syntax for using variables. I know in my example I set the value for var1 and var2 manually. But it was dynamically assigned, I need to put that value in the function.

How about this:

var1 = myrandomnum + 1
var2 = myrandomnum + 3

How would I script var1 and var2 into the function?

getURL(&quot;javascript:myfunction(<var1>, <var2>)&quot;)

Thanks again for replying :)
 
I'm no expert in javascript and I can't really get it working either when trying to use variables rather than the data itself. I do think it may be possible to make it work with an associative array syntax... Will investigate this further.
However, I presently can get those variables from the Flash movie, doing things the other way around. I'm calling a javascript function in the movie, which in turns gets the variables from the movie.
It goes something like this:
Code:
my_var1 = &quot;HELLO!&quot;;
on (press) {
    getURL (&quot;javascript:my_getfunction()&quot;);
}

And the javascript function:

function my_getfunction()
{	var jvar1 = document.
flashfile
Code:
.GetVariable(&quot;_root.my_var1&quot;)
		alert(jvar1)
}

This assumes flashfile is the ID in the <object> tag and the name in the <embed> tag, and that the swLiveConnect=true is set in the <embed> tag for use of this with NS.

Regards,
new.gif
 
Well got it to work if the variables hold numeric values...

The Following:
Code:
on (press) {
my_var1 = 100;
my_var2 = 2000;
getURL (&quot;javascript:my_passfunction(&quot;+my_var1+&quot;,&quot;+my_var2+&quot;)&quot;);
}

In combination with this java function:
Code:
function my_passfunction(var1,var2){
	document.write(&quot;This is var1 = &quot;+var1 + &quot;<br>And this is var2 = &quot; +var2);
	}
But it still won't work with variables holding strings such as:
my_var1 = &quot;Hello&quot;;
my_var2 = &quot;World!&quot;;

But even if I get it working (I'm not giving up already!), maybe the other method in my above post is easier since one function will &quot;automatically&quot; detect either numeric or string values.

Regards,
and might I be blessed with your vote!

new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top