github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

hotchpotch / as3rails2u

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 11
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Switch Branches (1)
    • master ✓
  • Switch Tags (0)
  • Branch List
Sending Request…

my as3 library — Read more

  Cancel

http://rails2u.com/

  Cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

remove old documents 
Yuichi Tateno (author)
Mon Apr 28 01:56:27 -0700 2008
commit  113c00677c1c1807e1f40060a4a49e8681a2831d
tree    73d503f8d58c87977e5cae8f55011d725559311a
parent  48ca2157ca4a4adf7b225c00eb654b5950436a8a
as3rails2u / src / com / rails2u / net / URLLoaderWithTimeout.as src/com/rails2u/net/URLLoaderWithTimeout.as
100644 54 lines (48 sloc) 1.695 kb
edit raw blame history
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
package com.rails2u.net
{
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
 
    /*
* URLLoader with Timeout
* loader.addEventListener(IOErrorEvent.IO_ERROR,
* function(e:*):void { trace('timeout!') });
* loader.loadWithTimeout(request, 30);
*/
    public class URLLoaderWithTimeout extends URLLoader
    {
        public function URLLoaderWithTimeout(request:URLRequest=null)
        {
            super(request);
        }
        
        public function loadWithTimeout(request:URLRequest, timeout:Number = 30):void
        {
            addEventListener(Event.COMPLETE, cancelTimeoutError, false, 1, true);
            observeTimeout(timeout);
            load(request);
        }
        
        private var observeTimer:Timer;
        private function observeTimeout(sec:Number):void
        {
            observeTimer = new Timer(sec * 1000, 1);
            observeTimer.addEventListener(
               TimerEvent.TIMER, timeoutError, false, 1, true
            );
            observeTimer.start();
        }
        
        private function cancelTimeoutError(e:Event):void
        {
            if (observeTimer) {
                observeTimer.removeEventListener(TimerEvent.TIMER, timeoutError);
            }
        }
        
        private function timeoutError(e:TimerEvent):void
        {
            dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, 'request timeout'));
            observeTimer = null;
        }
    }
}
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server