0

当 HtmlLoader.load() 失败时,有没有办法触发错误事件?

当没有互联网连接时,COMPLETE 事件永远不会被触发。我希望能够告诉用户“没有连接,关闭当前窗口并执行其他操作。”

4

2 回答 2

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);
    }
于 2013-07-11T09:43:41.250 回答
-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>
于 2013-07-15T17:21:43.550 回答