View Full Version : JSFL - CS3 addEventListener() question
Hi. Ive been able to use fl.addEventListerner to check if a document has been changed. Great! Only thing is that I'm building a swf window app and wondering if anyone has tried to execute (MMExecute) the command from the swf and actually get at return value in AS every time the document changes? I.e. the event funtion executes :confused:
this is what it looks like in AS:
var myString = "myFunction = function () { fl.trace('document has changed'); } ; fl.addEventListener("documentChanged", myFunction);"
MMExecute(myString);
...and thats the point. you can get a return value from MMExecute normally but how would you be able to recieve the return value from the event function?? or am i missing something?
drukepple
03-02-2009, 07:56 PM
Did you ever find a solution? I am currently now asking the very same question.
drukepple
03-02-2009, 08:33 PM
Found a solution!
It has more to with ExternalInterface and swfPanel.call().
JSFL scripts can access all SWF Panels in the app (they only show up in the array if the panel has been opened once in the session). Unfortunately there's no easy way to get a specific panel, so we have to do this
// JSFL
var panels = fl.swfPanels;
var myPanel;
for (var i = 0; i < panels.length; i++) {
if (panels[i].name == "My Panel Name") {
myPanel = panels[i];
break;
}
}
Once you have the swfPanel, you can use call(). I'm a little unclear on what the second parameter is; seems like it can only be string, and that you can't pass a third argument. I think. Anyway:
// JSFL
fl.addEventListener("documentChanged", onDocumentChanged);
function onDocumentChanged() {
if (myPanel) {
myPanel.call("documentChanged", "true");
}
}
Meanwhile, your WindowSWF needs to register a function with ExternalInterface:
// ActionScript 3
ExternalInterface.addCallback("documentChanged", onDocumentChanged);
// ... elsewhere ...
private function onDocumentChanged(arg:String):void {
// Do your stuff here!
}
I was able to do the JSFL part from an MMExecute. It was a long String with lots of quote and newline escapes, but it worked.
So as long as you have the SWF panel name right, and match up the ExternalInterface name, it should work.
EDIT:
Should have mentioned that this only works in Flash CS4. the swfPanel object wasn't introducted until then.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.