views:

1156

answers:

2

How do i pass three arguments using external interface in flash to a java script function and get back output and display it in flash?

+2  A: 

AS3:

var percent:int = Math.round(100 * done/total);

// pass 3 arguments to javascript
var result:Object = call("progress", { percent:percent, phase:"building", third:"baggage" });

// display what comes back
label.text = "js returned: " + result.status;
if (result.status == "ack")
    continue;
//....

public function call(func:String, args:Object = null):Object
{
   // check to see if we're in a container
   if (ExternalInterface.available)
      return ExternalInterface.call(func, args);
   else
      return { status:"fail" };
}

javascript:

<script>
function progress(info)
{
    if (info.phase == "building")
         $("#status").html("Progress: " + info.percent + "% done building");
    //...
    return { status:"ack" };
}
</script>
Scott Evernden
A: 
import flash.external.ExternalInterface;
var para:Array = new Array();
send_btn.addEventListener(MouseEvent.CLICK, clickListener);
function clickListener(eventObj:Object ):void {
    para.push(mean.text);
    para.push(std.text);
    para.push(points.text);
    trace("click > " + para);
    var output =ExternalInterface.call("calc",int(para[0]),int(para[1]),int(para[2]) );
out.text = output;
}

this is the code i am using to call a function calc which takes three arguments in java script, is this the right way of doing it and how can i get arguments back from javascript and display them in flash