I'm trying something different, seems like ExternalInterface API might be my answer to send a button name to my form POST.
In my SWF for my button I have this:
Code:
set ("buttonPressed", "pest");
import flash.external.ExternalInterface;
// Register so that it is possible to call from JavaScript in containing HTML
ExternalInterface.addCallback("getBtnName", null, getBtnName);
submitBtn.addEventListener("click", clickListener);
function clickListener(eventObj:Object):Void {
ExternalInterface.call("getFlashBtn", buttonPressed);
getURL("javascript:flashFormSubmit();");
}
getFlashBtn() is a function in my html form page:
Code:
var foo = null;
function getFlashBtn(btnname) {
foo = btnname;
}
function flashFormSubmit()
{
var myForm = document.forms[0];
var bn = document.getElementById('bname');
bn.value = foo;
myForm.submit();
}
as you can see I then send the buttonname that was supposedly sent by AS to a textfield, and then post the form using getUrl() with my js function.
Problem is, my form is not submitting. It seems the eventlistener is not firing. "submitBtn" is the instance name of my button. I'm not sure what is wrong, any ideas?
Start with the example from the flash doc, it works and is allmost the same.
The difference I think I see is, you kept out the JS part which handles the different browsers.
To send data AS -> JS you only need in JS the function you call , f.i.
function thisMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function makeCall(str) {
thisMovie("myflashmoviename").asFunc(str);
}
and in AS
Code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, asFunc);
function asFunc(str:String):Void {
// do something with str
}
Never accept the first 'impossible' unless it comes from a lady.
I have been looking at the Flash docs at MM and basically see exactly what you are saying, but it just doesn't work. I tried to adjust it based on what you wrote, but I'm doing something wrong I cannot see.
Maybe my eventListener is not firing or something, but absolutely nothing happens. Here is what I have right now. In my Flash doc I have, in the main layer:
Code:
import flash.external.ExternalInterface;
submitBtn.addEventListener("click", doClick);
function doClick(eventObj:Object):Void {
// Call JavaScript function jsFunc
ExternalInterface.call("jsFunc", "testing"); // send "testing" as a test str
getURL("javascript:flashFormSubmit();");
};
In my HTML Doc:
Code:
function flashFormSubmit()
{
var myForm = document.forms[0];
myForm.submit();
}
// This function "jsFunc" will be called from ActionScript
// take the test string (str) from AS and put it as the value of my form field...
function jsFunc(str) {
var bn = document.getElementById('bname');
bn.value = str;
}
This seemingly makes sense, but no dice.... I can't even begin to tell you how frustrating this is.
Maybe you can attach your fla? I attach the file I use for testing when I think I made a mistake somewhere. It allways works over here. Yes, it is the example of MM. I use the 'external' functions in a scorm compatible module, it gives me no problems except ...
... wait a minute ...
IE somehow uses a swf from cache even if it is changed. Monday I had similar problem with Firefox, that's why now I use IE and hand-empty the cache (if you use this button it seems IE doesn't really delete all).
I had lots of prblems because I changed the (local) swf while IE kept using the old version from cache.
Never accept the first 'impossible' unless it comes from a lady.