Greetings, all. I am new to these forums and new to using SWFObject. I think I've got most of it puzzled out, but I'm wondering if someone could help me out. I am wondering what the correct usage of the "getVariable" function is, and if it will do what I want. Essentially, I have a .swf file that I need to pass quite a bit of information to. This code was originally written using the object and embed tags, and information was sent using the SetVariable functions. However, I am trying to use these same flash files in a slightly different environment, and that method no longer works. For the most part, SWFObject seems to be the solution that I need. However, I am in need of getting some values back from the .swf file. However, when the getVariable function is called, no values are returned.
A prime example would be the following code I have. The variable "httext" simply returns the necessary HTML code for display within a textarea. I do understand that SWFObject has a similar function, but as I didn't create these .swf files, I don't want to monkey with something I don't know how to fix, so I need to get the "httext" variable back from the .swf file. It goes a little something like this:
var so = new SWFObject(player, "mymovie", "380", "500", "9", "#ffffff"); so.addVariable(...); ... textarea.value = so.getVariable("httext");
As far as I can tell, everything else works fine. However, "undefined" is displayed in my textarea. Any information you can give would be greatly appreciated, and if there is more specific code you would like to see that would help, please let me know. I'm not 100% sure on what's needed. Thanks again.
Just so I understand you correctly, you are wanting to get variables OUT of the flash file and set it on a textarea within your html page.
I am guessing that you were originally using the FSCommand actions of setVariable / getVariable. In this case you need to add a few things to your swfObject definition. It has been 3+ years since I have used FSCommand, so
1. add so.addParam("allowScriptAccess", "always"); 2. add so.addParam("swliveconnect", "true"); (to ensure you are allowed to call the scripts)
3. Add a seperate javascript block in your HTML page which will catch your FSCommand calls. If your id as above is "mymovie", then the beginning name of the DoFSCommand has to match that. e.g.
function mymovie_DoFSCommand(command, args) { if (command == "messagebox") { alert(args); } // ... more conditional statements to catch you flash commands }
As always, start off as simple as you can and build it up from there. For every <param> node in your original <object> definition, add the same values to your swfObject definition. The other javascript you had on your original page should remain unchanged (ensure you name the swfObect flash name the same as your original "id" parameter)
BTW, if you are running flash 8+, and testing locally, you will need to add the folder you are running from as a trusted source in order to see it all qworking (this is not an issue if it is deployed in a webserver). You can add the folder by going to the below location and adding your project folder (if you run FF and IE, you will need to do it x2). I usually have a top level folder like c:\dev which I add, and always put my local pojects under that folder (that way you only have to add 1 location rather than a new folder every new project)
Aran, thanks so much for the information. Allow me to expand a little bit on what's going on. The flash application is basically a quiz/poll application created by my company for use on Myspace. The user fills out a big form on our website, then javascript sends all the information to the swf object and kicks out the necessary <object> and <param> tags for the user to copy/paste into their profile. So it kind of "compiles" the flash application with the information they provided.
I have not added any parameters with addParam() as of yet, I probably should. I'm still trying to figure out exactly how the original code works so I can recreate it on the website I am building. I will take your comments and begin working on the project again today, and come back with any roadblocks. Thanks again for the detailed information, it is much appreciated!
James
EDIT: I did run into the security issue right away and have since taken care of that, but I do thank you for the heads up!
Well, it's still not working. Right now, the only variable I'm worried about getting out of the flash is the "htheight" variable, which is the height of the swf file. This is dynamic because the amount of questions and answers determines the height of the "movie". The "httext" variable I'm not concerned about because I can create that in Javascript, but the height I need. I added the two parameters "allowScriptAccess" and "swliveconnect", but it still isn't grabbing the htheight variable.
I looked into the DoFSCommand function, but I'm not 100% clear on how to use it to get the information I need. I've been banging my head against this for 2 days now, so I think I'm just not seeing it. If you could provide some more detailed information, I would be greatly appreciative. Thanks again for the information thus far.
Note that using FSCommand in Flash only works in IE (it doesn't work in Firefox).
In my experience, FSCommand should be avoided whenever possible.
If you need to pass variables from a Flash file to Javascript, I recommend using Flash's ExternalInterface class. It's pretty easy to use if you're at least a little a familiar with Javascript.
You might need to post some actual pages to move this forward, as I don't know what you have done correctly / incorrectly.
To add to what Philip said.
I agree that FSCommand is not the best option these days. If you don't want to / can't modify the orginal source than I guess you don't have much option though.
External interface is only available in flash 8 or above. If you do decide to rewrite the flash files to update the way you are communicating, and you need it to be compatible with flash 6/7 too, then have a look at the flash/javascript integration kit : http://osflash.org/projects/flashjs
It is a clever library which allows you to sent complex objects (arrays etc) to/from flash. It basically serialises native AS objects and js object into xml, and then converts them back to native types on the other side.
Aran, thanks again. I'll try and post some code later (I just got into work right now) for you, I understand that it's probably necessary at this point. The only knowledge I have of Flash is what I've been able to glean over the past couple of days, so I'm extremely new to this. I did see the Flash/Javascript Integration kit, as well as the implementation in SWFObject. It's not that I don't want to or can't modify the original source code, it's that I simply don't know how. But there are a couple of Flash gurus here at work that might be able to give me a hand in that. I'm still working on this, so I will keep you updated and will post some relevant code when I have the opportunity. Thanks again for all the help, it's much appreciated!