8/6/2010 12:48:46 AM
Title:
Calling repeatedly.
I have a code like this.
private function browseURL():void
{
var url1:URLRequest = new URLRequest("http://192.168.1.180/alert/poll.php");
loader1.addEventListener(Event.COMPLETE, LoadCompleted1);
loader1.load(url1);
function LoadCompleted1(e:Event):void
{
res = loader1.data;
req.action = "convert";
req.text = res
req.voice = "engfemale2";
srv.send(req);
showAlert(res);
}
}
public function showAlert(res:String):void
{
var alert : Alert = new Alert();
//Alert.show(alert.toString());
// alert.text = "hello";
Alert.show(res + " ID " + id,"Message",4,this,alertListener);
function alertListener(eventObj:CloseEvent):void
{
if(eventObj.detail == Alert.OK)
{
// Alert.show(alert.toString(),"",4,this);
}
else
{
}
}
}
each time this function is executed the alert count will also be increased.
why this is happening.
please give me a solution.
8/6/2010 1:26:18 AM
what is alert count clarify
8/6/2010 8:04:40 AM
By Alert count i mean when the showAlert() function is executed.
It will show the alert containing the response string.
When i run the program first it will come once on the button click on browseURL() function and on second click twice and so on.This is my problem.
8/6/2010 8:40:25 AM
ok , actually you have declared the "LoadCompleted1" locally inside the browseURL function . Whenever you call browseURL function it adds listener to the function, so as many times you call the function you are attaching a new listener but not removing the old one. You need to remove the listener first and then attach the new listener. Add the below line just before the line you are adding listener.
loader1.removeEventListener(Event.COMPLETE, LoadCompleted1);