PDA

View Full Version : Can I call a function in my SWF and pass it a parameter from JavaScript in the page?



jOEL
April 29th, 2004, 11:37 AM
Hello.
I'm trying to call a function in frame 1 of my SWF and also pass it a parameter.

I need to do this from elsewhere on the embedding HTML page using JavaScript.

For example call the function flashFunction(foo);

Does this require a listener in Flash that listens for the call, excepts "foo" and then calls the flashFunction and passes "foo" to it?

Can this be called directly without a listener?
Can this be done at all?

Any help would be greatly appreciated.

// jOEL

kode
April 29th, 2004, 11:52 AM
You can use the FlashVars property (http://www.macromedia.com/support/flash/ts/documents/flashvars.htm) to pass the parameter to the Flash movie and then call the function as you normally would in the 1st frame of the movie.

jOEL
April 29th, 2004, 11:57 AM
You can use the FlashVars property (http://www.macromedia.com/support/flash/ts/documents/flashvars.htm) to pass the parameter to the Flash movie and then call the function as you normally would in the 1st frame of the movie.

yeah, I use FlashVars quite a bit - works awesome.
In this instance though I need to pass parameters into the SWF without reloading the page.

kode
April 29th, 2004, 12:07 PM
Oh! In that case, you can use JavaScript to set a variable in the Flash movie, and use the Object.watch() method to execute the code whenever the value of the variable is changed. :)

http://www.macromedia.com/support/flash/ts/documents/set_variables.htm#javascript

function myFunction(foo) {
statement(s);
}
function callMyFunction(prop, oldval, newval) {
myFunction(newval);
return newval;
}
var foo;
this.watch("foo", callMyFunction);

jOEL
April 29th, 2004, 12:15 PM
Awesome!
At first glance, that looks like exactly what I was looking for.
Greatly appreciated.
Have a blessed day.

// jOEL

kode
April 29th, 2004, 12:34 PM
Sure - Hope you can figure it out from here, or yell if you need some more help. ;)

jOEL
May 5th, 2004, 07:13 AM
This worked great!
Thanx a bunch kode.
// jOEL

kode
May 5th, 2004, 08:17 AM
You're welcome, Joel. :)