My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.hatch.net
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.Timer;

public class URLLoaderDeluxe extends URLLoader
{
private var _timeoutTimer:Timer;
public var timeout:Number; // default timeout value

public static const TIMEOUT:String = 'loaderTimeout';

[Event(name="loaderTimeout", type="flash.events.Event")]

public function URLLoaderDeluxe(timeout:Number = 1000, request:URLRequest=null)
{
this.timeout = timeout;
_timeoutTimer = new Timer(timeout);
super(request);
}

override public function load(request:URLRequest):void
{
_timeoutTimer.addEventListener(TimerEvent.TIMER, handleTimeout);
_timeoutTimer.delay = timeout;

addEventListener(IOErrorEvent.IO_ERROR, handleLoadActivity);
addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleLoadActivity);
addEventListener(Event.COMPLETE, handleLoadActivity);
addEventListener(ProgressEvent.PROGRESS, handleLoadActivity);
addEventListener(Event.OPEN, handleLoadActivity);

super.load(request);
_timeoutTimer.start();
}

override public function close():void
{
killTimer();
super.close();
}

private function handleLoadActivity(event:Event):void
{
killTimer();
}

private function killTimer(event:Event = null):void
{
removeEventListener(IOErrorEvent.IO_ERROR, handleLoadActivity);
removeEventListener(SecurityErrorEvent.SECURITY_ERROR, handleLoadActivity);
removeEventListener(Event.COMPLETE, handleLoadActivity);
removeEventListener(ProgressEvent.PROGRESS, handleLoadActivity);
removeEventListener(Event.OPEN, handleLoadActivity);

_timeoutTimer.reset();
_timeoutTimer.removeEventListener(TimerEvent.TIMER, handleTimeout);

if(event)
super.dispatchEvent(event.clone());
}

private function handleTimeout(event:TimerEvent):void
{
killTimer();
super.dispatchEvent(new Event(TIMEOUT, true));
// this.dispatchEvent(new Event(TIMEOUT, true));
// var dis:EventDispatcher = new EventDispatcher(this);
// dis.dispatchEvent(new Event(TIMEOUT, true));
}
}
}

Change log

r83 by andyghatch on Nov 23, 2009   Diff
add additional handle to for load progress
Go to: 
Project members, sign in to write a code review

Older revisions

r81 by andyghatch on Aug 28, 2009   Diff
new URLLoader extension with timeout
All revisions of this file

File info

Size: 2283 bytes, 78 lines
Powered by Google Project Hosting