0

I'm trying to create a swfPanel for Flash CS5.5 using JSFL. I created my interface in flash and try to communicate with a JSFL command. So, in my .fla file, I use an ExternalInterface with callBack to call a specific function in JSFL, and then swfPanel.call() for the return. The problem I encounter is that I can't pass an Array as argument for the call function (after the AS3 function name). Here's the code :

In AS3 :

function init():void{
    ExternalInterface.addCallback("callBackPanel", JsflCallback);
    MMExecute("fl.runScript( fl.configURI + \"AirMobileFramework/AirMobileFrameworkPanel.jsfl\", \"checkSettings\" );");
}

function JsflCallback(... args):void{
    jsTrace("callback");
}

function jsTrace(str:String):void{
    MMExecute("fl.trace(\"" + str + "\");");
}

In JSFL :

function checkSettings(){   
    var fileSettingsUrl = fl.configURI + "AirMobileFramework/settings.fwk";
    var exist = FLfile.exists(fileSettingsUrl);
    var result = new Array("settings", exist);

    if(!exist){
        FLfile.write(fileSettingsUrl, "");
    } else {
        result.push(FLfile.read(fileSettingsUrl));
    }

    callPanelBack(result);
}

function callPanelBack(result){
    fl.trace("result: " + result.length + " > " + typeof result + " >> " + result[0]);
    var panel;
    if(fl.swfPanels.length > 0){ 
        for(x = 0; x < fl.swfPanels.length; x++){
            if(fl.swfPanels[x].name == "AirMobileFramework"){ 
                panel = fl.swfPanels[x];
                panel.call("callBackPanel", result); 
                break; 
            } 
        }
    } else {
        fl.trace("No existing panel");
    }
}

When calling panel.call("callBackPanel", result[0], result[1]); there is no problem, my callback is well called, but when using panel.call("callBackPanel", result); I've an error : La ou les erreurs JavaScript suivantes se sont produites lors de l'exécution de AirMobileFramework : La ou les erreur(s) JavaScript suivantes se sont produites :

Any idea ??

2
  • You never stated what the error was? Also alert result right before you do panel.call verify everything is as seems. Commented Sep 8, 2011 at 17:54
  • I've checked the values contained in my result array, and it's all good. Concerning the error, the flash IDE doesn't describe the error's reason. It only says that there has been a Javascript error. (no error id, no line number for that error, nothing more than 'An error occurred while executing AirMobileFramework') I can't understand what mistake I did. when tracing result content, I obtain : RESULT => LENGTH: 3, TYPEOF: object, CONTENT: settings,true, (the 3rd value in result is "" because settings.fwk is empty) Commented Sep 12, 2011 at 14:09

2 Answers 2

0

I would guess that it's because JSFL can't parse an array. In the example you give, with result[0], result[1] you have seperate values (probably strigns or numbers), and that should give no problem.

What I would do is this:

panel.call("callBackPanel", result.join("@*$");

and in the as3 function simply just arg.split("@*$")

if your input could have the string "@*$", then you could simply make a call to the SWF for each item in result, and when you're done with the loop there, tell the SWF to gather the things - like this:

function callPanelBack(result){
    fl.trace("result: " + result.length + " > " + typeof result + " >> " + result[0]);
    var panel;
    if(fl.swfPanels.length > 0){ 
        for(x = 0; x < fl.swfPanels.length; x++){
            if(fl.swfPanels[x].name == "AirMobileFramework"){ 
                panel = fl.swfPanels[x];
                panel.call("callBackPanelStart"); 
                for(var i=0; i < result.length; i++){
                    panel.call("callBackPanelArgument", result[i])
                }
                panel.call("callBackPanelEnd"); 
                break; 
            } 
        }
    } else {
        fl.trace("No existing panel");
    }
}

and then in AS3:

function callBackPanelStart():void
{
    jsflArray = [];
}

function callBackPanelArgument(argument:*):void
{
    jsflArray.push(argument);
}

function callBackPanelEnd():void
{
    // execute whatever you must on the result
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your answer. Having no answer from anybody for a while, I also choosed the solution to join my arguments with "[PARAM]" String, and it works well ! Your second solution seems also interesting !! But I'm really surprised that JSFL couldn't parse an array as argument.
Yeah that does seem really strange. By in my experience JSFL is really lacking support. Some of the features Adobe mention in their documentation doesn't even work!
0

This is what you need to pass Arrays back and forth from JSFL: http://exanimo.com/actionscript/jsflinterface/

And worth looking at this as well, once it's released in a week or so: http://www.xjsfl.com

1 Comment

Thanks a lot for your answer. But I can't understand how I could return array argument from JSFL to actionscript using the exanimo lib ? It's JSFLInterface seems great and very useful but it only allows you to call a simple JSFL methods from actionscript, and in my case, I use JSFL external scripts, which one would call actionscript with an array as argument. (maybe I haven't understood something about exanimo lib, so I need your lights on that). Regarding your xJSFL framework, I'm still waiting its release !! (great job !!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.