|
JavaScript from AS3
package
{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.external.ExternalInterface;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class ActionScriptToJavaScript extends Sprite
{
private var wordInput:TextField;
public function ActionScriptToJavaScript()
{
wordInput = new TextField();
wordInput.type = TextFieldType.INPUT;
wordInput.maxChars = 20;
wordInput.border = true;
wordInput.restrict = "a-z";
wordInput.height = 20;
wordInput.width = 120;
wordInput.background = true;
wordInput.backgroundColor = 0xFFFFFF;
addChild(wordInput);
var theButton:Sprite = new Sprite();
theButton.graphics.lineStyle(0x000000);
theButton.graphics.beginFill(0x000000, .2);
theButton.graphics.drawRect(0, 0, 85, 20);
theButton.buttonMode = true;
var ButtonTXT:TextField = new TextField();
ButtonTXT.selectable = false;
ButtonTXT.text = "alert my words";
theButton.x = wordInput.x+130;
ButtonTXT.x = theButton.x+5;
addChild(ButtonTXT);
addChild(theButton);
theButton.addEventListener(MouseEvent.CLICK, doAlertHandler);
}
private function doAlertHandler(event:MouseEvent):void
{
if (ExternalInterface.available)
{ExternalInterface.call("alertthese", wordInput.text);}
}
}
}
The Javascript used with this example :
function alertthese(words)
{
alert(words);
}
|