views:

1676

answers:

2

As a Flash newbie I found this very confusing and it cost me a couple of hours. Answering my own question here in case anyone has the same problem.

Technically you should be able to do something like this:

<param name="movie" value="movie.swf?param=value" />
<embed src="movie.swf?param=value" ...

Or this:

<PARAM NAME "FlashVars" VALUE="param=value">
<EMBED .... FlashVars="param=value">

Both should create a variable in the _root or _level0 scope called 'param' with the correct value.

These are documented here

However, in my particular version of Flash (CS4, ActionScript 2.0), this didn't work.

A: 

The answer which worked for me is to modify the AC_FL_RunContent() function in the HTML generated by CS4, adding the parameters which need to be passed to the movie, e.g.

'flashvars', 'param=value',

It seems this function overwrites anything which is directly specified in the OBJECT and EMBED tags or on the query string.

There may be better solutions out there...

lrussell
A: 

You could also use ExternalInterface to call a JavaScript function on the HTML page that returns a value. This has the added value that you don't have to hardcode the value and you can pass parameters to the JavaScript function.

In the Flash Movie:

import flash.external.ExternalInterface;

function getOutsideValue(argToJS:String):Void {
 var jsArgument:String = argToJS;
 var result:Object = ExternalInterface.call("stringAdd", jsArgument);
}

In the Javascript in the HTML page:

function stringAdd(inptStr){
 var strToAdd = inptStr;
 strToAdd += " added text";
 return strToAdd;
}

So when you call the ActionScript function in Flash:

getOutsideValue("I get");

It will return:

I get added text

Note that ExternalInterface can also be used to call functions inside the Flash from JavaScript. Examples of both can be found here: http://kb2.adobe.com/cps/156/tn_15683.html

It seems that this is the recommended way to passing information to and from SWF movies, it certainly is more dynamic and powerful than just using hard coded values.

Charlie boy
Thanks, that is a nice solution :)
lrussell