addEventListener останавливается после любого Alert.showbox

1 view
Skip to first unread message

FedY@

unread,
Jun 28, 2008, 10:31:11 AM6/28/08
to ruFlex
к примеру есть скрипт который проверяет соединение с интернетом в Air
приложение!


public function ConnectionManager():void{

var headRequest:URLRequest = new URLRequest();

headRequest.method = "HEAD";

headRequest.url = "http://www.google.com";

var u:URLMonitor = new URLMonitor(headRequest);

u.addEventListener(StatusEvent.STATUS,statusChanged);

u.start();

}



// check the results and alert the user if no connection is found

public function statusChanged(status:StatusEvent):void{

if(status.code == "Service.unavailable"){

isConnected = false;

Alert.show("This application requires\nan internet connection",
"ERROR");

} else {

isConnected = true;
}

}

пока не будет выдано сообщение Alert.show, будет работать прекрасно
проверка на соединение!... если убрать алерт и поюзать программу с
откл. и вкл. интернетом и записывать просто в статус.бар то все
нормально происходит! :( В чем проблема ?

Сергей Кононенко

unread,
Jun 28, 2008, 11:03:58 PM6/28/08
to ruf...@googlegroups.com
FedY@ пишет:
Значит, когда в статус бар записываешь, сборщик мусора не убирает. А тут
по идее он должен почистить после события.- у тебя же это локальные
переменные.

FedY@

unread,
Jun 29, 2008, 8:24:20 AM6/29/08
to ruFlex
Тоесть мне нужно
var headRequest:URLRequest = new URLRequest();
var u:URLMonitor = new URLMonitor(headRequest);
объявить сразу после открытия тега Script ? тоесть сделать
глобальными?

FedY@

unread,
Jun 29, 2008, 2:39:07 PM6/29/08
to ruFlex
После вынесения переменных глобально - имею ошибку:
TypeError: Error #2007: Parameter url must be non-null.
at flash.net::URLStream/load()
at air.net::URLMonitor/checkStatus()[G:\Acro_root_apms\Frameworks
\ServiceMonitor\src\air\net\URLMonitor.as:133]
at air.net::ServiceMonitor/start()[G:\Acro_root_apms\Frameworks
\ServiceMonitor\src\air\net\ServiceMonitor.as:101]
at FirstAir/init()[C:\Documents and Settings\Admin\My Documents\Flex
Builder 3\FirstAir\src\FirstAir.mxml:23]
at FirstAir/___FirstAir_WindowedApplication1_creationComplete()[C:
\Documents and Settings\Admin\My Documents\Flex Builder 3\FirstAir\src
\FirstAir.mxml:3]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks
\projects\framework\src\mx\core\UIComponent.as:9051]
at mx.core::UIComponent/set initialized()[E:\dev\3.0.x\frameworks
\projects\framework\src\mx\core\UIComponent.as:1167]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x
\frameworks\projects\framework\src\mx\managers\LayoutManager.as:698]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.0.x\frameworks
\projects\framework\src\mx\core\UIComponent.as:8460]
at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.0.x\frameworks
\projects\framework\src\mx\core\UIComponent.as:8403]


<mx:Script>
<![CDATA[
import air.net.URLMonitor;
import flash.events.StatusEvent;
import flash.net.URLRequest;
import mx.controls.Alert;

public var isConnected:Boolean = false;
public var headRequest:URLRequest = new URLRequest();
public var u:URLMonitor = new URLMonitor(headRequest);



public function init():void{
this.status="Checking Internet connection...";
headRequest.method = "HEAD";
headRequest.url = "http://www.google.com";
u.addEventListener(StatusEvent.STATUS,statusChanged);
u.start();
}


public function statusChanged(status:StatusEvent):void{
trace("checking");
if(status.code == "Service.unavailable"){
this.status="NOT Connected";
isConnected = false;
} else {
this.status="Connected";
isConnected = true;
}
}

private function check():void
{
trace("message");
if(isConnected){
stat.text = "GOOD";
}else{
stat.text = "Проверьте интернет соединение";
}
}
]]>
</mx:Script>

Denis Kolyako

unread,
Jun 29, 2008, 3:44:11 PM6/29/08
to ruf...@googlegroups.com
FedY@ wrote:
> После вынесения переменных глобально - имею ошибку:
>
Попробуйте обернуть start() в try…catch.

--
Денис Коляко
______________________________________________________________________
e...@timezero.ru | http://etcs.ru | http://www.timezero.com

Reply all
Reply to author
Forward
0 new messages