Copy link to clipboard
Copied
Hi,
I've been with this all day with no practical results, although I think I understand the logic of this.
I have a project that will have three SWF's and an ActiveX component. This ActiveX will have to accept messages from all three SWF (they are separate due to layout options). Practically the comunication is one way (SWF - > ActiveX), but I want to manage both ways, in case it's need in the future.
Using the ExternalInterface class I'm able to send values to Javascript, but I'm stuck the other way around, and it seems that, as much as I change names and function, the result is the same. I can't read values coming from JS.
I tested for ExternalInterface availability and the SWF says "true".
In the AS I have:
ExternalInterface.addCallback("sendUserToFlash", setUserName);
public function setUserName(str:String):void {
medidasForm.nombreTx.text = str;
}
... And in JS I have:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
//Sends Text to the AS callback
function formSend() {
thisMovie("Left").sendUserToFlash("User Name");
}
function getTextFromFlash() {
formSend();
}
Making a ExternalInterface.call works.
In the HTML the SWF has the ID called "Left".
The JS console of FlashBug returns an error wich is:
thisMovie("Left").sendUserToFlash is not a function http://localhost/mcoda/callbacks.js Line 13
But I thinks that's because it doesn't know that this function is inside an SWF and not in JS.
I think this is a simple and common error, but I'm running out of options. Any suggestions?
Thanks.
Copy link to clipboard
Copied
Well, it seems no one is having a clue of waht's happening.
Meanwhile I came across a post on Stackoverflow.com site about this question.
It seems that the code generated by Dreamweaver to place the SWF contents doesn't work if you want to make this type of callbacks for every browser.
Has most of us know there are differences in browsers interpretation of HTML and Javascript, and this is one of those cases where you must contemplate these differences.
After my post yesterday, I manage to put this to work in IE8, with the Dreamweaver code. In one side is good but on the other hand is bad. Meanwhile FF and Chrome gave me an JS error whenever I tried to execute the JS function in HTML, IE didn't gave me any error and executed. But in other occasions IE always "ate" the code given, with errors or not, and this is one more.
The conclusion in Stackoverflow is to use the "embed" tag instead of the "object" tag in HTML to place the SWF. The first one interpreted by FF, Chrome and Safari, and the second is interpreted by IE.
You can see this entry in: http://stackoverflow.com/questions/4631322/as3-externalinterface-works-in-ie-but-not-firefox to see what you have to do.
The work I'm doing is a bit more complicated because I have three SWF and maybe I'll have to make separate JS functions to work with them.
The example HTML code I'm using now is:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="right" align="middle" width="340" height="750">
<param name="movie" value="right_interface.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src='right_interface.swf' height='750' width='340' id='right_e' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
</object>
Hope this helps anyone with the same problems.
Cheers.
Copy link to clipboard
Copied
hi
never use dreamweaver to embed a swf - use swfobject instead (see: http://code.google.com/p/swfobject/) - even Adobe recommend it...
Copy link to clipboard
Copied
Hi Lee,
Thanks. I didn't know about that. Probably will help solving what's happening now.
Has I said before I'm trying to send messages to an ActiveX. I can see that the SWF sends messages and that JavaScript catches them, but it seems that afterwards JS can't send them to the ActiveX, while making the same messages with only HTML and JS it works.
I tried referencing the object directly by it's id and also with document JS reference, but I got no results.
This project is to work only in IE so I'll see if this works, maybe it's a question of some parameters that gets in the way.
Best regards.
Copy link to clipboard
Copied
you can use the online generator (see: http://www.bobbyvandersluis.com/swfobject/generator/index.html) to grab suitable html and it's all 100% browser compatible so it may resolve your problem
Copy link to clipboard
Copied
Thanks again Lee.
I dind' t reply immediatly, since I wasn't with this project in the weekend.
I altered the HTML to SWFObject but still no go. It seems that Flash can call JS functions, but if inside this JS function is a call to a (in this case) ActiveX it's not executed, although if I have a "console.log" command, for Firebug purposes, it is executed.
I don't think I can call directly the ActiveX. Or is there a possibility of doing this?
Thanks.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Lee,
First of all, thank you for staying and helping me thinking how to solve this. defenitly your suggestion has taken me a bit further to understanding how this might work.
After you last suggestion I made some changes and a little experiment to see if this was actually comunicating the way I want. I placed two similar and separate SWF with the purpose of one throwing a message to the other.
For registering the SWF I used:
swfobject.registerObject("Up", "9.0.0");
swfobject.registerObject("Down", "9.0.0");
Then I used some JS functions like this:
var jsReady = false;
var mensagem="";
function isReady() {
return jsReady;
}
function pageInit() {
jsReady = true;
}
function sendMsg(str){
mensagem=str;
sendBack();
}
function sendBack(){
console.log("sendBack");
document.getElementById('Down').showJSMessage("Ola");
}
Everything worked has supposed to, and this tells also that if you use document.getElementById it also works in IE (I'm using IE8). It seems although that it works after some seconds of the page being loaded(!?).
But it seems that applying this notation for calling the ActiveX, doesn't work. Now I have to take small steps to see if this is to be run from a server or not, because it seems that with a simple HTML button calling a function like the following directly from the folder, it works.
function loadAvatar(){
AvatarScene.loadObject();
}
"AvatarScene" is the ActiveX id.
If you come up with any crazy ideia, please do. I'll keep this thread posted if anything works.
Thanks.
Copy link to clipboard
Copied
Solved!
Wraping it up, this is what I was trying to do:
1- I have a web page with an ActiveX component that has some methods to inject information from JavaScript... or should I say JScript!
2- I made an interface with three different Flash modules. Each of them have different purposes but comunicate with the same ActiveX;
3- The first problem was a mixup where I was trying to make this two way comunication using an Apache server, since I couldn't run the ActiveX in my computer. Afterall this would have to run in a local way, no server whatsoever;
After LeeBurrows suggestions I changed the way I embed the SWF files to a more standard way than DW does it. Then came the headaches solely because I was trying to comunicate with JavaScript. Since ActiveX is a old technology, it used something called JScript which for example doesn't need the "document.getElementById" to identify the object that I wich to talk to. You simply need to put the object id and the method you which to call, like this myObject.doThis();
Another problem is that this only works with IE, and probably, the older the better. I was using IE8 and sometimes with compatibility view on.
Then I changed the AS3 way of calling the JScript. First I used the recent ExternalInterface class, and changed to the old fscommand. In the Apache server with firebug Extension and Javascript console in IE I was seeing that the comunication was beeing made correctly, but somehow the ActiveX was not receiving the information.
The last step was doing this locally, but the security warnings start to fire. Nevertheless I was able to see that the messages were passing by. So I had to go to the Global Security Settings and placed the folder I was working on has authorized to run script code. And it worked.
With fscommand or ExternalInterface it works.
This was nothing I didn't knew about, but has I'm used to work in a server environment, this was not crossing my mind.
Now things should run smoothly.
Cheers.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more