Ver Mensaje Individual
  #9 (permalink)  
Antiguo 09/01/2006, 22:08
wwwmaster
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Con FLash 8:

Example
The following example calls the JavaScript function sayHello() in the HTML page that contains the SWF. The call is made by using the ExternalInterface.call() method.

import flash.external.*;

var greeting:String;
var btn:MovieClip = createButton(100, 30, 0xCCCCCC);
btn.onPress = function() {
greeting = String(ExternalInterface.call("sayHello", "browser"));
this.mcTxt.text = greeting; // >> Hi Flash.
}

function createButton(width:Number, height:Number, color:Number):MovieClip {
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
var mcFmt:TextFormat;

mc.beginFill(color);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);

mcFmt = new TextFormat();
mcFmt.align = "center";
mcFmt.bold = true;

mc.createTextField("mcTxt", depth, 0, 0, width, height);
mc.mcTxt.text = "Call JS Function";
mc.mcTxt.setTextFormat(mcFmt);

return mc;
}


For the previous example to work properly, you should be copy and paste the following code into the containing HTML page. Unless the HTML page is hosted on a server, your browser may alert you with a security warning.

<script>
function sayHello(name) {
alert(">> Hello " + name + ".");
return ">> Hi Flash.";
}
</script>