header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Kiran
Points:0
Posts:0
Answered

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.



1
Justin
Points: 600
Posts:0
8/6/2010 1:26:18 AM



what is alert count clarify

2
Kiran
Points: 0
Posts:0
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.

3
Justin
Points: 600
Posts:0
Accepted Answer
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);


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 7+2 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions