当HtmlLoader.load()失败时,有没有办法触发错误事件?
当没有互联网连接时,COMPLETE事件永远不会被触发。我希望能够告诉用户“没有连接,关闭当前窗口并执行其他操作。”
答案 0 :(得分:0)
当然,但你必须为某些事件监听URLRequest的实例
//your code to load page in to HtmlLoader
var html:HTMLLoader = new HTMLLoader();
var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");
configureListeners(urlReq);
html.width = stage.stageWidth;
html.height = stage.stageHeight;
html.load(urlReq);
addChild(html);
//add all listeners you need
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
答案 1 :(得分:-1)
此代码适用于Flex 4
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
var html:HTMLLoader = new HTMLLoader();
var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");
configureListeners(html);
html.width = 800;
html.height = 800;
html.load(urlReq);
conteiner.addChild(html);
}
//add all listeners you need
private function configureListeners(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS,progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
.
.
.
.
.
.
]]>
</fx:Script>
<s:SpriteVisualElement id="conteiner">
</s:SpriteVisualElement>
</s:WindowedApplication>