Hi, Venian...
I'm sorry for my english...
This is my full code:
package
{
import flash.net.NetConnection;
import flash.net.Responder;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
import flash.display.Sprite;
import fl.controls.Button;
import fl.controls.TextInput;
import fl.controls.TextArea;
import flash.text.TextFormat;
public class ComplVisivo extends Sprite
{
private var nc:NetConnection;
private var textInput1:TextInput;
private var textArea:TextArea;
private var readBtn:Button;
private var writeBtn1:Button;
private var removeBtn:Button;
private var rtmpNow:String;
private var good:Boolean;
private var responder:Responder;
private var format:TextFormat;
private var checkBtn:Boolean;
public function ComplVisivo ()
{
nc=new NetConnection();
rtmpNow="rtmp://192.168.1.68/complvisivo/storeFile";
nc.connect (rtmpNow,"Writer");
nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
writeBtn1=new Button();
writeBtn1.x=265, writeBtn1.y=125;
writeBtn1.setSize(80,30);
writeBtn1.addEventListener (MouseEvent.CLICK,writeFile1);
addChild (writeBtn1);
readBtn=new Button();
readBtn.x=400, readBtn.y=275;
readBtn.width=90;
readBtn.addEventListener (MouseEvent.CLICK,readFile);
addChild (readBtn);
removeBtn=new Button();
removeBtn.x=400, removeBtn.y=300;
removeBtn.width=90;
removeBtn.addEventListener (MouseEvent.CLICK,removeFile);
addChild (removeBtn);
format=new TextFormat;
format.font = "Verdana";
format.bold=true;
format.size=20;
textInput1=new TextInput();
textInput1.setStyle("textFormat",format);
textInput1.x=115, textInput1.y=125;
textInput1.setSize(100,30);
addChild (textInput1);
textArea = new TextArea();
textArea.width=100, textArea.height=200;
textArea.x=400, textArea.y=70;
addChild (textArea);
}
private function checkConnect (e:NetStatusEvent):void
{
good=e.info.code == "NetConnection.Connect.Success";
if (good)
{
writeBtn1.label = "Conferma";
}
}
private function writeFile1 (e:MouseEvent):void
{
checkBtn = (writeBtn1.label == "Conferma" && textInput1.text != "" );
if (checkBtn)
{
nc.call ("WriteNow",null,textInput1.text+"\n");
writeBtn1.label = "Fatto";
}
}
private function removeFile (e:MouseEvent)
{
nc.call("RemoveNow",null);
textArea.text="";
writeBtn1.label = "Conferma";
readBtn.label = "Verifica";
textInput1.text = "";
}
private function readFile (e:MouseEvent):void
{
if (readBtn.label == "Verifica" && writeBtn1.label == "Fatto" )
{
responder=new Responder(showFile);
nc.call ("ReadNow",responder);
readBtn.label = "Fatto";
}
else if (readBtn.label == "Verifica" && writeBtn1.label == "Conferma" )
{
responder=new Responder(showFile);
nc.call ("ReadNow",responder);
}
}
private function showFile (fileBack:Array):void
{
if (fileBack != null)
{
var backLen:uint=fileBack.length;
for (var c:uint; c< backLen; c++)
{
textArea.appendText (fileBack + "\n");
}
}
else
{
textArea.text="Empty File";
}
}
}
}
I have to confirm the text into textInput1 with Enter and with WriteBtn1.
Can you Help me?
Thanks.
Emiliano.
So you want function WriteFile1 to shoot when pressing WriteBtn1 and Enter. The same function for two triggers, right?
the code for the mouseEvent is good but you need to more things to do:
1. Set writeFile1 event listener to null as in the following example:
private function writeFile1 (e:MouseEvent=null)
{
checkBtn = (writeBtn1.label == "Conferma" && textInput1.text != "" );
if (checkBtn)
{
nc.call ("WriteNow",null,textInput1.text+"\n");
writeBtn1.label = "Fatto";
}
2. Write the keyboard function:
textInput1.addEventListener(KeyboardEvent.KEY_DOWN, HitEnter);
function HitEnter(e:KeyboardEvent) {
if (e.keyCode == 13) {
writeFile1();
}
}
Setting the listener of the function to null allows other type of listeners to trigger the function. I don't know if text components have direct keyboard listeners ( i almost never use components) but they should have. Other wise look in help about text component.