├── README.mkd ├── docs ├── all-classes.html ├── all-index-A.html ├── all-index-B.html ├── all-index-C.html ├── all-index-D.html ├── all-index-E.html ├── all-index-F.html ├── all-index-G.html ├── all-index-H.html ├── all-index-I.html ├── all-index-J.html ├── all-index-K.html ├── all-index-L.html ├── all-index-M.html ├── all-index-N.html ├── all-index-O.html ├── all-index-P.html ├── all-index-Q.html ├── all-index-R.html ├── all-index-S.html ├── all-index-T.html ├── all-index-U.html ├── all-index-V.html ├── all-index-W.html ├── all-index-X.html ├── all-index-Y.html ├── all-index-Z.html ├── appendixes.html ├── asdoc.js ├── br │ └── com │ │ └── stimuli │ │ └── loading │ │ ├── BulkLoader.html │ │ ├── BulkProgressEvent.html │ │ ├── Connection.html │ │ ├── LazyBulkLoader.html │ │ ├── LazyXMLLoader.html │ │ ├── LoadingItem.html │ │ ├── class-list.html │ │ ├── lazyloaders │ │ ├── LazyBulkLoader.html │ │ ├── LazyJSONLoader.html │ │ ├── LazyXMLLoader.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── loadingtypes │ │ ├── BinaryItem.html │ │ ├── ImageItem.html │ │ ├── LoadingItem.html │ │ ├── SoundItem.html │ │ ├── URLItem.html │ │ ├── VideoItem.html │ │ ├── XMLItem.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ └── package-detail.html ├── class-summary.html ├── cookies.js ├── images │ ├── collapsed.gif │ ├── detailHeaderRule.jpg │ ├── detailSectionHeader.jpg │ ├── expanded.gif │ ├── inherit-arrow.gif │ ├── inheritedSummary.gif │ ├── logo.jpg │ ├── titleTableBottom.jpg │ ├── titleTableMiddle.jpg │ └── titleTableTop.jpg ├── index-list.html ├── index.html ├── mxml-tags.html ├── package-frame.html ├── package-list.html ├── package-summary.html ├── print.css ├── style.css └── title-bar.html ├── examples ├── serialized-loaders │ ├── AC_RunActiveContent.js │ ├── SerializedTestMain.as │ ├── serialized-test.fla │ ├── serialized-test.html │ └── serialized-test.swf └── simple-example │ ├── SimpleExampleMain.as │ ├── simple-example.fla │ └── simple-example.swf ├── inspector ├── Bootstrapper.as ├── BulkLoaderInspectorBootstrapper.fla ├── BulkLoaderInspectorBootstrapper.swf └── fl-project │ ├── .actionScriptProperties │ ├── .flexProperties │ ├── .project │ ├── .settings │ └── org.eclipse.core.resources.prefs │ ├── src │ ├── BulkLoaderInspectorContainer.mxml │ └── br │ │ └── com │ │ └── stimuli │ │ └── loading │ │ ├── BulkLoaderInspectorPanel.mxml │ │ ├── ItemDetailCanvas.mxml │ │ ├── LoaderInspector.mxml │ │ └── LoadingItemRenderer.as │ └── www │ ├── BulkLoaderInspectorContainer.swf │ ├── index.html │ └── swfobject.js ├── src └── br │ └── com │ └── stimuli │ └── loading │ ├── BulkLoader.as │ ├── BulkProgressEvent.as │ ├── lazyloaders │ ├── LazyBulkLoader.as │ ├── LazyJSONLoader.as │ └── LazyXMLLoader.as │ ├── loadingtypes │ ├── BinaryItem.as │ ├── ImageItem.as │ ├── JSONItem.as │ ├── LoadingItem.as │ ├── SoundItem.as │ ├── URLItem.as │ ├── VideoItem.as │ └── XMLItem.as │ └── utils │ └── SmartURL.as ├── swc └── bulk_loader.swc └── tests ├── bin ├── AC_RunActiveContent.js ├── TestSuite.html └── TestSuite.swf ├── src ├── BulkLoaderTestRunner.mxml └── br │ └── com │ └── stimuli │ └── loading │ └── tests │ ├── AudioContentTest.as │ ├── AutoIdTest.as │ ├── BaseAssyncTest.as │ ├── BulkLoaderTestSuite.as │ ├── BulkStartTest.as │ ├── ClearMemoryTest.as │ ├── ClearNowTest.as │ ├── CollectionTestCase.as │ ├── ErrorResumeTest.as │ ├── GetClassDefinitionTest.as │ ├── GuessTypeTest.as │ ├── HasItemTest.as │ ├── HostPriorityTest.as │ ├── InstanceRetrivalTestCase.as │ ├── LazyJSONLoaderTest.as │ ├── LazyXMLInternalsTest.as │ ├── LazyXMLLoaderTest.as │ ├── LoadNowTest.as │ ├── LoaderImageItemTest.as │ ├── LoaderItemAVM1MovieTest.as │ ├── LoaderItemMovieTest.as │ ├── OnCompleteTest.as │ ├── OnErrorTest.as │ ├── PauseAllResumeTest.as │ ├── ProgressEventsTest.as │ ├── RegisterNewTypeTest.as │ ├── ReloadTest.as │ ├── RemoveAllSimpleTest.as │ ├── RemoveAllTest.as │ ├── RemoveFailedItemTest.as │ ├── ResumeAllTest.as │ ├── ResumeTest.as │ ├── SmartURLTest.as │ ├── StartPausedTest.as │ ├── StringSubstituionTest.as │ ├── TwoItemsWithTheSameURLTest.as │ ├── URLItemTest.as │ ├── VideoContentPausedAtStartTestCase.as │ ├── VideoContentTest.as │ └── XMLItemTest.as └── third-parties └── src ├── br └── com │ └── stimuli │ └── kisstest │ ├── TestCase.as │ ├── TestResult.as │ ├── TestRunner.as │ ├── TestSuite.as │ ├── events │ ├── AssertionFailedEvent.as │ ├── AssertionSuccessEvent.as │ ├── TestEvent.as │ └── TestResultEvent.as │ └── runners │ ├── GUIFlexRunner.mxml │ └── TraceRunner.as └── com └── adobe └── serialization └── json ├── JSON.as ├── JSONDecoder.as ├── JSONEncoder.as ├── JSONParseError.as ├── JSONToken.as ├── JSONTokenType.as └── JSONTokenizer.as /README.mkd: -------------------------------------------------------------------------------- 1 | BulkLoader is a minimal library written in Actionscript 3 (AS3) that aims to make loading and managing complex loading requirements easier and faster. BulkLoader takes a more dynamic, less architecture heavy approach. Few imports and making heavy use of AS3's dynamic capabilities, BulkLoader has a one-liner feel that doesn't get in your way. 2 | 3 | BulkLoader hides the complexity of loading different data types in AS3 and provides a unified interface for loading, accessing and events notification for different types of content. 4 | 5 | This library is licensed under an open source MIT license. 6 | Features: 7 | 8 | * Connection pooling. 9 | * Unified interface for different loading types. 10 | * Unified progress notification. 11 | * Events for individual items and as groups. 12 | * Priority 13 | * Stop and resuming individually as well as in bulk. 14 | * Cache management. 15 | * Statistics about loading (latency, speed, average speed). 16 | * Various kinds on progress indication: ratio (items loaded / items to load), bytes , and weighted percentage. 17 | * Configurable number of retries. 18 | * Configurable logging. 19 | * Various assets types (XML, NetStreams, Swfs, Images, Sound, Text Files) 20 | 21 | Design goals: 22 | 23 | * Minimal imports. 24 | * Few method to learn. 25 | * Consistent interface, regardless of content type. 26 | 27 | BulkLoader gracefully handles progress notification in these use cases: 28 | 29 | * Few connections to open: bytes total can be used instantly. 30 | * Many connections opened: progress by ratio 31 | * Many connections opened for data of widely varying sizes: progress by weight. 32 | 33 | 34 | Useful links: 35 | 36 | * The [FAQ](http://github.com/arthur-debert/BulkLoader/wiki/FAQ) has the answer to the most common questions. 37 | * The [WIKI](http://github.com/arthur-debert/BulkLoader/wiki) has a lot of user guides. 38 | * The [Original announcement](http://www.stimuli.com.br/trane/2007/nov/25/loading-reloaded/) . 39 | * The [Mailing list](http://groups.google.com/group/bulkloader-users) . This is where support request and usage questions should be directed. 40 | * The [Online documentation](http://media.stimuli.com.br/projects/bulk-loader/docs/) for asdoc style help. 41 | 42 | Thank you 43 | -------------------------------------------------------------------------------- /docs/all-classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | All Classes - BulkLoader 6 | 7 | 8 | 9 | 10 | 11 |

12 | All Classes 13 |

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
BulkLoader
BulkProgressEvent
LoadingItem
SmartURL
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/appendixes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Appendixes 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 |
 AppendixDescription
39 |

40 | 41 |
42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/Connection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | br.com.stimuli.loading.Connection 9 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
Packagebr.com.stimuli.loading
Classpublic class Connection
41 |

42 | Class description. 43 |

44 |
45 |
46 |
47 | 48 |
49 |
Public Methods
50 | 51 | 52 | 53 | 54 | 55 | 61 | 62 |
 MethodDefined by
   56 |
57 | Connection()
58 |
59 |
60 |
Connection
63 |
64 | 68 |
69 | 70 |
Constructor detail
71 | 72 | 73 | 74 | 75 | 76 |
Connection()constructor
77 |
78 | public function Connection()

79 |

80 |
81 |
82 |
83 |
84 |

85 | 86 |
87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/class-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | br.com.stimuli.loading - BulkLoader 6 | 7 | 8 | 9 | 10 | 11 |

12 | Package br.com.stimuli.loading 13 |

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
Classes
BulkLoader
BulkProgressEvent
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/lazyloaders/class-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | br.com.stimuli.loading.lazyloaders - API Documentation 6 | 7 | 8 | 9 | 10 | 11 |

12 | Package br.com.stimuli.loading.lazyloaders 13 |

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
Classes
LazyBulkLoader
LazyJSONLoader
LazyXMLLoader
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/lazyloaders/package-detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | br.com.stimuli.loading.lazyloaders Summary 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |
32 |
33 |
34 |
35 | 36 |
Classes
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
 ClassDescription
 LazyBulkLoader A serialized version of af BulkLoader instance.
 LazyJSONLoader 
 LazyXMLLoader 
51 |

52 |
53 |

54 | 55 |
56 |
57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/loadingtypes/class-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | br.com.stimuli.loading.loadingtypes - BulkLoader 6 | 7 | 8 | 9 | 10 | 11 |

12 | Package br.com.stimuli.loading.loadingtypes 13 |

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
Classes
LoadingItem
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/loadingtypes/package-detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | br.com.stimuli.loading.loadingtypes Summary 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |
32 |
33 |
34 |
35 | 36 |
Classes
37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 |
 ClassDescription
 LoadingItem 43 | An class used in BulkLoader instances.

.

46 |

47 |
48 |

49 | 50 |
51 |
52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/br/com/stimuli/loading/package-detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | br.com.stimuli.loading Summary 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |
32 |
33 |
34 |
35 | 36 |
Classes
37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 | 46 | 48 | 49 |
 ClassDescription
 BulkLoader 43 | Manages loading for simultaneous items and multiple formats.
 BulkProgressEvent 47 | An event that holds information about the status of a BulkLoader.
50 |

51 |
52 |

53 | 54 |
55 |
56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/cookies.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ADOBE SYSTEMS INCORPORATED 4 | // Copyright 2006-2007 Adobe Systems Incorporated 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Adobe permits you to use, modify, and distribute this file 8 | // in accordance with the terms of the license agreement accompanying it. 9 | // 10 | //////////////////////////////////////////////////////////////////////////////// 11 | 12 | /** 13 | * Read the JavaScript cookies tutorial at: 14 | * http://www.netspade.com/articles/javascript/cookies.xml 15 | */ 16 | 17 | /** 18 | * Sets a Cookie with the given name and value. 19 | * 20 | * name Name of the cookie 21 | * value Value of the cookie 22 | * [expires] Expiration date of the cookie (default: end of current session) 23 | * [path] Path where the cookie is valid (default: path of calling document) 24 | * [domain] Domain where the cookie is valid 25 | * (default: domain of calling document) 26 | * [secure] Boolean value indicating if the cookie transmission requires a 27 | * secure transmission 28 | */ 29 | function setCookie(name, value, expires, path, domain, secure) 30 | { 31 | document.cookie= name + "=" + escape(value) + 32 | ((expires) ? "; expires=" + expires.toGMTString() : "") + 33 | ((path) ? "; path=" + path : "") + 34 | ((domain) ? "; domain=" + domain : "") + 35 | ((secure) ? "; secure" : ""); 36 | } 37 | 38 | /** 39 | * Gets the value of the specified cookie. 40 | * 41 | * name Name of the desired cookie. 42 | * 43 | * Returns a string containing value of specified cookie, 44 | * or null if cookie does not exist. 45 | */ 46 | function getCookie(name) 47 | { 48 | var dc = document.cookie; 49 | var prefix = name + "="; 50 | var begin = dc.indexOf("; " + prefix); 51 | if (begin == -1) 52 | { 53 | begin = dc.indexOf(prefix); 54 | if (begin != 0) return null; 55 | } 56 | else 57 | { 58 | begin += 2; 59 | } 60 | var end = document.cookie.indexOf(";", begin); 61 | if (end == -1) 62 | { 63 | end = dc.length; 64 | } 65 | return unescape(dc.substring(begin + prefix.length, end)); 66 | } 67 | 68 | /** 69 | * Deletes the specified cookie. 70 | * 71 | * name name of the cookie 72 | * [path] path of the cookie (must be same as path used to create cookie) 73 | * [domain] domain of the cookie (must be same as domain used to create cookie) 74 | */ 75 | function deleteCookie(name, path, domain) 76 | { 77 | if (getCookie(name)) 78 | { 79 | document.cookie = name + "=" + 80 | ((path) ? "; path=" + path : "") + 81 | ((domain) ? "; domain=" + domain : "") + 82 | "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /docs/images/collapsed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/collapsed.gif -------------------------------------------------------------------------------- /docs/images/detailHeaderRule.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/detailHeaderRule.jpg -------------------------------------------------------------------------------- /docs/images/detailSectionHeader.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/detailSectionHeader.jpg -------------------------------------------------------------------------------- /docs/images/expanded.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/expanded.gif -------------------------------------------------------------------------------- /docs/images/inherit-arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/inherit-arrow.gif -------------------------------------------------------------------------------- /docs/images/inheritedSummary.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/inheritedSummary.gif -------------------------------------------------------------------------------- /docs/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/logo.jpg -------------------------------------------------------------------------------- /docs/images/titleTableBottom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/titleTableBottom.jpg -------------------------------------------------------------------------------- /docs/images/titleTableMiddle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/titleTableMiddle.jpg -------------------------------------------------------------------------------- /docs/images/titleTableTop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/docs/images/titleTableTop.jpg -------------------------------------------------------------------------------- /docs/index-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Adobe Flex 2 Language Reference 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |

Index

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 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 |
AN
BO
CP
DQ
ER
FS
GT
HU
IV
JW
KX
LY
MZ
117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Adobe Flex 2 Language Reference 8 | 9 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | <body> 46 | 47 | <h2>Frame Alert</h2> 48 | 49 | <p> 50 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 51 | <br> 52 | Link to <a href="package-summary.html">Non-frame version.</a> 53 | 54 | </p> 55 | 56 | </body> 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/mxml-tags.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | MXML Only Components - Adobe Flex 2 Language Reference 10 | 11 | 12 | 13 | 14 | 15 | 16 |

MXML Only Components

17 | 18 | <mx:Binding> 19 |
20 | 21 | <mx:Component> 22 |
23 | 24 | <mx:Metadata> 25 |
26 | 27 | <mx:Model> 28 |
29 | 30 | <mx:Script> 31 |
32 | 33 | <mx:Style> 34 |
35 | 36 | <mx:XML> 37 |
38 | 39 | <mx:XMLList> 40 |
41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Adobe Flex 2 Language Reference 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | <body> 20 | 21 | <h2>Frame Alert</h2> 22 | 23 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 24 | <br> 25 | Link to<a href="package-summary.html">Non-frame version.</a> 26 | 27 | </p> 28 | 29 | </body> 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/package-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Package List - BulkLoader 6 | 7 | 8 | 9 | 10 | 11 | 12 |

13 | Packages 14 |

15 | 16 | 17 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 |
br.com.stimuli.loading 18 |
19 |
br.com.stimuli.loading.loadingtypes 23 |
24 |
br.com.stimuli.loading.utils
30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | All Packages 6 | 7 | 8 | 9 | 10 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
 PackageDescription
 br.com.stimuli.loading 
 br.com.stimuli.loading.loadingtypes 
 br.com.stimuli.loading.utils 
48 |

49 | 50 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /docs/print.css: -------------------------------------------------------------------------------- 1 | /* 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // 4 | // ADOBE SYSTEMS INCORPORATED 5 | // Copyright 2005-2007 Adobe Systems Incorporated 6 | // All Rights Reserved. 7 | // 8 | // NOTICE: Adobe permits you to use, modify, and distribute this file 9 | // in accordance with the terms of the license agreement accompanying it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////// 12 | */ 13 | 14 | body { 15 | color: #000000; 16 | background: #ffffff; 17 | font-family: "Times New Roman", Times, serif; 18 | font-size: 12pt; 19 | } 20 | a { 21 | text-decoration: none; 22 | color: #000000; 23 | } 24 | pre { 25 | white-space: -moz-pre-wrap; /* Mozilla */ 26 | white-space: -pre-wrap; /* Opera 4-6 */ 27 | white-space: -o-pre-wrap; /* Opera 7 */ 28 | word-wrap: break-word; /* IE */ 29 | } 30 | .titleTableTopNav, .titleTableSubNav, .logoImage { 31 | display: none; 32 | } 33 | .packageFrame { 34 | display: none; 35 | } 36 | .titleTableSubTitle { 37 | font-weight: bold; 38 | } 39 | .classHeaderTableLabel { 40 | padding-right: 10px; 41 | vertical-align: top; 42 | } 43 | .showHideLinks { 44 | display: none; 45 | } 46 | html>body code { 47 | font-size: 10pt; 48 | } 49 | .summaryTableTitle, .detailSectionHeader { 50 | font-size: 14pt; 51 | font-weight: bold; 52 | padding-top: 15px; 53 | padding-bottom: 5px; 54 | } 55 | .summaryTable { 56 | border: 1px solid #000000; 57 | border-collapse: collapse; 58 | width: 100%; 59 | } 60 | .summaryTableDescription { 61 | padding-bottom: 20px; 62 | } 63 | .summaryTableSignatureCol, .summaryTableOwnerCol, .summaryTableLastCol, .summaryTableCol { 64 | border: 1px solid #000000; 65 | } 66 | .summaryTablePaddingCol { 67 | border: 1px solid #000000; 68 | border-right: 0px; 69 | } 70 | .summaryTableInheritanceCol, .summaryTableOperatorCol, .summaryTableStatementCol, .summaryTableSecondCol { 71 | border: 1px solid #000000; 72 | border-left: 0px; 73 | } 74 | .summaryTableLastCol { 75 | vertical-align: top; 76 | } 77 | .detailHeader { 78 | font-size: 13pt; 79 | padding-top: 100px; 80 | } 81 | .detailHeaderName { 82 | font-weight: bold; 83 | } 84 | .detailHeaderType { 85 | padding-left: 5px; 86 | } 87 | .detailHeaderRule { 88 | background: #FF0000; 89 | } 90 | .seeAlso { 91 | padding-bottom: 20px; 92 | margin-top: -20px; 93 | } 94 | .innertable { 95 | border-collapse: collapse; 96 | } 97 | .innertable td,.innertable th { 98 | border: 1px solid #000000; 99 | padding-left: 5px; 100 | padding-right: 5px; 101 | } 102 | .listing { 103 | font-size: 10pt; 104 | } 105 | .feedbackLink { 106 | display: none; 107 | } 108 | .copyright { 109 | font-size: 10pt; 110 | } -------------------------------------------------------------------------------- /docs/title-bar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Adobe Flex 2 Language Reference 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
BulkLoader 26 | All Packages | All Classes | Index | No Frames   27 | 30 |

31 |
 
 
51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /examples/serialized-loaders/SerializedTestMain.as: -------------------------------------------------------------------------------- 1 | package{ 2 | import br.com.stimuli.loading.lazyloaders.LazyXMLLoader; 3 | import br.com.stimuli.loading.lazyloaders.LazyBulkLoader; 4 | import br.com.stimuli.loading.*; 5 | import br.com.stimuli.loading.loadingtypes.*; 6 | import br.com.stimuli.loading.BulkProgressEvent; 7 | import flash.events.*; 8 | import flash.display.*; 9 | import flash.media.Sound; 10 | import flash.media.Video; 11 | import flash.net.NetStream; 12 | 13 | public class SerializedTestMain extends MovieClip{ 14 | public var lazy : LazyXMLLoader; 15 | 16 | public function SerializedTestMain() : void{ 17 | // create a lazy instance 18 | lazy = new LazyXMLLoader("http://www.emptywhite.com/bulkloader-assets/lazyloader.xml", "theLazyLoader"); 19 | // special event so that can tell when the xml file is loaded and 20 | // then attach events to indivudual items 21 | lazy.addEventListener(LazyBulkLoader.LAZY_COMPLETE, onLazyInfoLoaded) 22 | // these are just like events to the regular BulkLoader instance 23 | lazy.addEventListener(Event.COMPLETE, onAllLoaded); 24 | lazy.addEventListener(ProgressEvent.PROGRESS, onAllProgress); 25 | // tells lazy loader to start 26 | lazy.start(); 27 | 28 | } 29 | 30 | public function onLazyInfoLoaded(evt : Event) : void{ 31 | 32 | trace("serialized data is ready!", lazy) 33 | // attach an event listener specific for the video: 34 | lazy.get("http://www.emptywhite.com/bulkloader-assets/movie.flv").addEventListener(BulkLoader.COMPLETE, onVideoComplete); 35 | } 36 | 37 | public function onVideoComplete(evt : Event) : void{ 38 | var theStream : NetStream = evt.target.content; 39 | trace("theStream", theStream); 40 | //... 41 | } 42 | 43 | public function onAllProgress(evt : BulkProgressEvent) : void{ 44 | trace(evt.ratioLoaded); 45 | } 46 | 47 | function onAllLoaded(evt : Event) : void{ 48 | trace("onAllLoaded", onAllLoaded); 49 | var xPos : int = 0; 50 | var yPos : int= 0; 51 | for each (var item : LoadingItem in lazy.items){ 52 | if (item.isImage()){ 53 | var b : Bitmap = lazy.getBitmap(item.id); 54 | //trace(item.loader.contentLoaderInfo.applicationDomain == ApplicationDomain.currentDomain ); 55 | addChild(b); 56 | if (b.width > 200){ 57 | b.width = 200; 58 | b.scaleY = b.scaleX; 59 | b.x = xPos; 60 | b.y = yPos; 61 | xPos += b.width + 10; 62 | if(xPos > 800){ 63 | xPos = 0; 64 | yPos += 200; 65 | } 66 | } 67 | }else if (item.isSound()){ 68 | var sound : Sound = lazy.getSound(item.url); 69 | sound.play(); 70 | } 71 | } 72 | } 73 | 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/serialized-loaders/serialized-test.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/examples/serialized-loaders/serialized-test.fla -------------------------------------------------------------------------------- /examples/serialized-loaders/serialized-test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | serialized-test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 40 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/serialized-loaders/serialized-test.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/examples/serialized-loaders/serialized-test.swf -------------------------------------------------------------------------------- /examples/simple-example/SimpleExampleMain.as: -------------------------------------------------------------------------------- 1 | package{ 2 | import br.com.stimuli.loading.BulkLoader; 3 | import br.com.stimuli.loading.BulkProgressEvent; 4 | import flash.events.*; 5 | import flash.display.*; 6 | import flash.media.*; 7 | import flash.net.*; 8 | 9 | public class SimpleExampleMain extends MovieClip{ 10 | public var loader : BulkLoader; 11 | public var v : Video; 12 | public var counter : int = 0; 13 | 14 | // simple example with few features 15 | // it takes a long time to download everything, it's over 17 mb 16 | public function SimpleExampleMain() { 17 | // creates a BulkLoader instance with a name of "main-site", that can be used to retrieve items without having a reference to this instance 18 | loader = new BulkLoader("main-site"); 19 | // set level to verbose, for debugging only 20 | loader.logLevel = BulkLoader.LOG_INFO; 21 | // now add items to load 22 | // simplest case: 23 | loader.add("http://www.emptywhite.com/bulkloader-assets/cats.jpg"); 24 | // use an "id" so the item can be retrieved later without a reference to the url 25 | loader.add("http://www.emptywhite.com/bulkloader-assets/shoes.jpg", {id:"bg"}); 26 | // add an item that should be loaded first (higher priority): 27 | loader.add("http://www.emptywhite.com/bulkloader-assets/samplexml.xml", {priority:20, id:"config-xml"}); 28 | // add a video, and force it to load paused 29 | loader.add("http://www.emptywhite.com/bulkloader-assets/movie.flv", {maxTries:6, id:"the-video", pausedAtStart:true}); 30 | // of course, options can be combined: 31 | loader.add("http://www.emptywhite.com/bulkloader-assets/chopin.mp3", {"id":"soundtrack", maxTries:1, priority:100}); 32 | 33 | // dispatched when ALL the items have been loaded: 34 | loader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded); 35 | 36 | // dispatched when any item has progress: 37 | loader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress); 38 | 39 | // now start the loading 40 | loader.start(); 41 | } 42 | 43 | public function onAllItemsLoaded(evt : Event) : void{ 44 | trace("every thing is loaded!"); 45 | // attach the vídeo: 46 | var video : Video = new Video(); 47 | // get the nestream from the bulkloader: 48 | var theNetStream : NetStream = loader.getNetStream("the-video"); 49 | addChild(video); 50 | video.attachNetStream(theNetStream); 51 | theNetStream.resume(); 52 | video.y = 300; 53 | // grab the images 54 | 55 | // you can get the content from the url: 56 | var bitmapCats : Bitmap = loader.getBitmap("http://www.emptywhite.com/bulkloader-assets/cats.jpg") 57 | bitmapCats.width = 200; 58 | bitmapCats.scaleY = bitmapCats.scaleX; 59 | addChild(bitmapCats); 60 | 61 | // you can get by the id as well (easier): 62 | var bitmapShoes : Bitmap = loader.getBitmap("bg") 63 | bitmapShoes.width = 200; 64 | bitmapShoes.scaleY = bitmapShoes.scaleX; 65 | bitmapShoes.x = 220; 66 | addChild(bitmapShoes); 67 | 68 | // get the sound: 69 | var soundtrack : Sound = loader.getSound("soundtrack"); 70 | soundtrack.play(); 71 | 72 | // get an xml file! 73 | var theXML : XML = loader.getXML("config-xml"); 74 | trace(theXML); 75 | } 76 | 77 | // this evt is a "super" progress event, it has all the information you need to 78 | // display progress by many criterias (bytes, items loaded, weight) 79 | public function onAllItemsProgress(evt : BulkProgressEvent) : void{ 80 | trace(evt.loadingStatus()); 81 | } 82 | } 83 | } 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /examples/simple-example/simple-example.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/examples/simple-example/simple-example.fla -------------------------------------------------------------------------------- /examples/simple-example/simple-example.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/examples/simple-example/simple-example.swf -------------------------------------------------------------------------------- /inspector/Bootstrapper.as: -------------------------------------------------------------------------------- 1 | package { import flash.display.*; import flash.events.*; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; /** * This is a simple bootstrapper that is able to load the BulkLoader inspector into a regular flash swf. * This code was taken from Jim Armstrong (algorithmist.wordpress.com) * * @langversion ActionScript 3 * @playerversion Flash 9.0.0 * */ public class Bootstrapper extends Sprite { private var __loadedClip:MovieClip; // loaded content cast as MovieClip private var __loader:Loader; // reference to external asset loader private var __application:*; // reference to loaded application () public function Bootstrapper() { __loadedClip = null; __loader = new Loader(); var info:LoaderInfo = __loader.contentLoaderInfo; info.addEventListener(Event.COMPLETE , __onComplete); info.addEventListener(IOErrorEvent.IO_ERROR , __onIOError ); } public function load(_file:String):void { var urlRequest:URLRequest = new URLRequest(_file); var loaderContext:LoaderContext = new LoaderContext(); loaderContext.applicationDomain = ApplicationDomain.currentDomain; __loader.load(urlRequest, loaderContext); } private function __onComplete(_evt:Event):void { addChild(__loader); __loadedClip = __loader.content as MovieClip; __loadedClip.addEventListener(Event.ENTER_FRAME, __onFlexAppLoaded); } // poll loaded Flex clip until application property is set (Flex completes its own internal initialization) private function __onFlexAppLoaded(_evt:Event):void { if( __loadedClip.application != null ) { __loadedClip.removeEventListener(Event.ENTER_FRAME, __onFlexAppLoaded); __application = __loadedClip.application; addChild(__loadedClip); } } private function __cleanup():void { var info:LoaderInfo = __loader.contentLoaderInfo; info.removeEventListener(Event.COMPLETE, __onComplete); info.removeEventListener(IOErrorEvent.IO_ERROR , __onIOError ); } private function __onIOError(_evt:IOErrorEvent):void { trace( "io error - check file names and location" ); } private function __onInitialize(_e:Event):void { __cleanup(); } } } -------------------------------------------------------------------------------- /inspector/BulkLoaderInspectorBootstrapper.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/inspector/BulkLoaderInspectorBootstrapper.fla -------------------------------------------------------------------------------- /inspector/BulkLoaderInspectorBootstrapper.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/inspector/BulkLoaderInspectorBootstrapper.swf -------------------------------------------------------------------------------- /inspector/fl-project/.actionScriptProperties: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /inspector/fl-project/.flexProperties: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /inspector/fl-project/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fl-project 4 | 5 | 6 | 7 | 8 | 9 | com.adobe.flexbuilder.project.flexbuilder 10 | 11 | 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.flexnature 16 | com.adobe.flexbuilder.project.actionscriptnature 17 | 18 | 19 | 20 | [source path] src 21 | 2 22 | /Users/arthurdebert/Documents/projects/bulk-loader/bulk-loader-git/src 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /inspector/fl-project/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Aug 03 07:58:13 BRT 2009 2 | eclipse.preferences.version=1 3 | encoding/=utf-8 4 | -------------------------------------------------------------------------------- /inspector/fl-project/src/BulkLoaderInspectorContainer.mxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /inspector/fl-project/src/br/com/stimuli/loading/BulkLoaderInspectorPanel.mxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /inspector/fl-project/src/br/com/stimuli/loading/ItemDetailCanvas.mxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /inspector/fl-project/src/br/com/stimuli/loading/LoadingItemRenderer.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading 2 | { 3 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 4 | 5 | import flash.events.Event; 6 | import flash.events.ProgressEvent; 7 | 8 | import mx.containers.HBox; 9 | import mx.controls.ProgressBar; 10 | import mx.controls.ProgressBarMode; 11 | 12 | public class LoadingItemRenderer extends HBox{ 13 | public var pb : ProgressBar; 14 | public var oldValue : Object; 15 | //public var src : Object; 16 | public function LoadingItemRenderer() 17 | { 18 | 19 | } 20 | 21 | 22 | 23 | 24 | 25 | override protected function createChildren() : void{ 26 | pb = new ProgressBar(); 27 | pb.mode = ProgressBarMode.MANUAL; 28 | pb.width = 170; 29 | pb.labelPlacement = "right"; 30 | pb.label = ""; 31 | pb.setStyle("trackHeight", 20); 32 | pb.setStyle("fontWeight", "normal"); 33 | addChild(pb); 34 | pb.setStyle("labelWidth", 50); 35 | pb.setStyle("isOverBar", false); 36 | pb.setStyle("verticalGap", 0); 37 | } 38 | 39 | override public function set data(value : Object):void{ 40 | if(oldValue){ 41 | oldValue.removeEventListener("progress", onItemProgress, false); 42 | oldValue.removeEventListener("complete", onDone, false); 43 | } 44 | oldValue = value; 45 | 46 | oldValue.addEventListener("progress", onItemProgress, false, 0, true); 47 | oldValue.addEventListener("complete", onDone, false, 0, true); 48 | updateProgress(value as LoadingItem); 49 | 50 | } 51 | 52 | public function onDone(evt : Event):void{ 53 | var src : LoadingItem = evt.target as LoadingItem; 54 | updateBarColor(src); 55 | } 56 | 57 | public function updateBarColor(item : LoadingItem) : void{ 58 | 59 | var c : uint = 0; 60 | var trackColors : Array = [0xE6EEEE,0xE6EEEE]; 61 | switch(item.status){ 62 | case LoadingItem.STATUS_FINISHED: 63 | c = 0x00FF00; 64 | break; 65 | case LoadingItem.STATUS_STARTED: 66 | c = 0x0000FF; 67 | break; 68 | case LoadingItem.STATUS_ERROR: 69 | c = 0xFF0000; 70 | trackColors = [0xFF0000,0xFF0000]; 71 | break; 72 | case LoadingItem.STATUS_STOPPED: 73 | c = 0x888888; 74 | break; 75 | } 76 | if(c != 0){ 77 | pb.setStyle(".barColor", c); 78 | pb.setStyle("trackColors", trackColors); 79 | } 80 | } 81 | 82 | public function onItemProgress(evt : ProgressEvent):void{ 83 | var src : LoadingItem = evt.target as LoadingItem; 84 | updateProgress(src); 85 | } 86 | 87 | public function updateProgress(src : LoadingItem) : void{ 88 | 89 | pb.setProgress(src.bytesLoaded, src.bytesTotal); 90 | pb.toolTip = src.bytesLoaded + "/" + src.bytesTotal; 91 | updateBarColor(src); 92 | 93 | pb.label= src.humanFiriendlySize; 94 | 95 | // trace(evt.bytesLoaded/ evt.bytesTotal) 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /inspector/fl-project/www/BulkLoaderInspectorContainer.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/inspector/fl-project/www/BulkLoaderInspectorContainer.swf -------------------------------------------------------------------------------- /inspector/fl-project/www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BulkLoader inspector panel 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 | 22 | 23 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/lazyloaders/LazyBulkLoader.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.lazyloaders{ 2 | import flash.events.*; 3 | import flash.net.*; 4 | import flash.display.*; 5 | import flash.media.Sound; 6 | import flash.utils.*; 7 | import flash.system.LoaderContext; 8 | import flash.system.ApplicationDomain; 9 | import flash.media.SoundLoaderContext; 10 | import br.com.stimuli.loading.BulkLoader; 11 | /** 12 | * Dispatched when the external file representing this serialized bulk loader intance has been downloaded and parse. At 13 | * this point the user can get references to all items and attach events to them accordingly. 14 | * 15 | * @eventType br.com.stimuli.loading.BulkProgressEvent.PROGRESS 16 | */ 17 | [Event(name="lazyComplete", type="flash.events.Event")]; 18 | /** A serialized version of af BulkLoader instance. This class allows you to keep external files with a complete description of what loading items should be loaded. This class is not meant to be used directly, but used as a base classes for specific data transports (xml, json). 19 | * 20 | */ 21 | public class LazyBulkLoader extends BulkLoader { 22 | namespace lazy_loader = "http://code.google.com/p/bulk-loader/"; 23 | lazy_loader var _lazyTheURL : URLRequest; 24 | /** @private */ 25 | lazy_loader var _lazyLoader : URLLoader; 26 | /** @private */ 27 | lazy_loader static const INT_TYPES : Array = ["maxTries", "priority"]; 28 | /** @private */ 29 | lazy_loader static const NUMBER_TYPES : Array = ["weigth"]; 30 | /** @private */ 31 | lazy_loader static const STRINGED_BOOLEAN : Array = ["preventCache", "pausedAtStart", "checkPolicyFile"]; 32 | public static const LAZY_COMPLETE : String = "lazyComplete"; 33 | 34 | public function LazyBulkLoader(url : *, name : String, numConnections : int = BulkLoader.DEFAULT_NUM_CONNECTIONS, logLevel : int = BulkLoader.DEFAULT_LOG_LEVEL){ 35 | 36 | if (url is String) { 37 | lazy_loader::_lazyTheURL = new URLRequest(url); 38 | } 39 | lazy_loader::_lazyTheURL = (lazy_loader::_lazyTheURL as URLRequest) || url; 40 | super(name, numConnections, logLevel); 41 | } 42 | 43 | /** Starts to fetch the external data that will define a BulkLoader instance when parsed. When the fetch operation 44 | * is done and the item is correctly parsed, it will dispatch an event with name LAZY_COMPLETE. 45 | */ 46 | override public function start(numConnections : int = -1):void { 47 | if (numConnections > 0){ 48 | this._numConnections = numConnections; 49 | } 50 | lazy_loader::_lazyLoader = new URLLoader(lazy_loader::_lazyTheURL); 51 | lazy_loader::_lazyLoader.addEventListener(Event.COMPLETE, lazy_loader::_lazyOnComplete, false, 0, true); 52 | } 53 | 54 | /** @private */ 55 | lazy_loader function _lazyOnComplete(evt : Event):void { 56 | lazy_loader::_lazyParseLoader(evt.target.data); 57 | dispatchEvent(new Event(LAZY_COMPLETE)); 58 | super.start(); 59 | } 60 | 61 | /** Useful subclasses should implement this method for a specific seralization method. The .start method will be called right after 62 | * the serialized data is parsed. 63 | * @param withData A String to be turned into a BulkLoader instance. 64 | * @private 65 | */ 66 | lazy_loader function _lazyParseLoader(withData : String) : void{ 67 | throw new Error("subclasses should implement a useful method for this"); 68 | } 69 | 70 | /** @private */ 71 | lazy_loader static function toBoolean(value : String):Boolean { 72 | if (value == "true" || value == "1" || value == "yes") { 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | override public function toString():String { 79 | return "[LazyBulkLoader] url: " + lazy_loader::_lazyTheURL.url + ", bulkloader: " + super.toString(); 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/lazyloaders/LazyJSONLoader.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.lazyloaders{ 2 | import br.com.stimuli.loading.*; 3 | import br.com.stimuli.loading.loadingtypes.*; 4 | import br.com.stimuli.loading.lazyloaders.*; 5 | import flash.events.*; 6 | import flash.net.*; 7 | import flash.display.*; 8 | import flash.media.Sound; 9 | import flash.utils.*; 10 | import flash.system.LoaderContext; 11 | import flash.system.ApplicationDomain; 12 | import flash.media.SoundLoaderContext; 13 | /** 14 | * @example Basic usage: 15 | var lazy : LazyJSONLoader = new LazyJSONLoader("sample-lazy.json", "myBulkLoader"); 16 | // listen to when the lazy loader has loaded the external definition 17 | lazy.addEventListener(Event.LAZY_LOADED, onLazyLoaded); 18 | // add regular events to the BulkLoader instance 19 | lazy.addEventListener(ProgressEvent.PROGRESS, onLazyProgress); 20 | lazy.addEventListener(Event.LAZY_LOADED, onAllItemsLoaded); 21 | 22 | function onLazyLoaded(evt : Event) : void{ 23 | // now you can add individual events for items 24 | onLazyLoaded.get("config").addEventListener(BulkLoader.COMPLETE, onConfigLoaded); 25 | ... 26 | } 27 | 28 | */ 29 | dynamic public class LazyJSONLoader extends LazyBulkLoader { 30 | private var _decodeFunc : Function; 31 | function LazyJSONLoader(url : *, name : String, numConnections : int = BulkLoader.DEFAULT_NUM_CONNECTIONS, logLevel : int = BulkLoader.DEFAULT_LOG_LEVEL){ 32 | super (url, name, numConnections, logLevel); 33 | } 34 | 35 | /** Reads a xml as a string and create a complete bulk loader from it. 36 | * @param withData The xml to be read as a string. 37 | * @private 38 | */ 39 | 40 | public function get decodeFunc() : Function { 41 | if (!Boolean(_decodeFunc)){ 42 | // defaults to adobe`s corelib decoder: 43 | var decoderClass : Object = getDefinitionByName("com.adobe.serialization.json.JSON"); 44 | _decodeFunc = decoderClass.decode; 45 | } 46 | return _decodeFunc; 47 | } 48 | 49 | public function set decodeFunc(value:Function) : void { 50 | _decodeFunc = value; 51 | } 52 | 53 | lazy_loader override function _lazyParseLoader(withData : String) : void{ 54 | var source : Object = decodeFunc(withData); 55 | stringSubstitutions = source["stringSubstitutions"] || undefined; 56 | _allowsAutoIDFromFileName = source["allowsAutoIDFromFileName"] || false; 57 | _numConnections = source["numConnections"] || BulkLoader.DEFAULT_NUM_CONNECTIONS; 58 | logLevel = source["logLevel"] || BulkLoader.DEFAULT_LOG_LEVEL; 59 | if (source["name"]){ 60 | _name = source["name"]; 61 | } 62 | var url : String; 63 | for each (var fileProp : Object in source["files"]) { 64 | var props : Object = fileProp; 65 | if (!String(props["url"])) { 66 | trace("[LazyBulkLoader] got a item files with no url, ignoring"); 67 | continue; 68 | } 69 | if (props["context"]){ 70 | var context : Object; 71 | if (BulkLoader.guessType(String(fileProp["url"])) == BulkLoader.TYPE_SOUND || fileProp["type"] == "sound") { 72 | context = new SoundLoaderContext(); 73 | } else { 74 | context = new LoaderContext(); 75 | } 76 | context.applicationDomain = ApplicationDomain.currentDomain; 77 | props[BulkLoader.CONTEXT] = context; 78 | }else if (fileProp["headers"]){ 79 | var oldHeaders : Object = fileProp["headers"]; 80 | fileProp["headers"]= []; 81 | for each(var headerObject : Object in oldHeaders){ 82 | for (var headerName : String in headerObject){ 83 | var theHeader : URLRequestHeader = new URLRequestHeader(headerName, headerObject[headerName]); 84 | fileProp["headers"].push(theHeader); 85 | } 86 | } 87 | } 88 | url = props["url"]; 89 | delete props["url"]; 90 | var theItem : LoadingItem = add(url, props); 91 | } 92 | } 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/loadingtypes/BinaryItem.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.loadingtypes { 2 | 3 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 4 | import br.com.stimuli.loading.BulkLoader; 5 | import flash.display.*; 6 | import flash.net.*; 7 | import flash.events.*; 8 | import flash.utils.*; 9 | 10 | /** @private */ 11 | public class BinaryItem extends LoadingItem { 12 | public var loader : URLLoader; 13 | 14 | public function BinaryItem(url : URLRequest, type : String, uid : String){ 15 | super(url, type, uid); 16 | } 17 | 18 | override public function _parseOptions(props : Object) : Array{ 19 | return super._parseOptions(props); 20 | } 21 | 22 | override public function load() : void{ 23 | super.load(); 24 | loader = new URLLoader(); 25 | loader.dataFormat = URLLoaderDataFormat.BINARY; 26 | loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); 27 | loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); 28 | loader.addEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false, 0, true); 29 | loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false, 0, true); 30 | loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); 31 | loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false, 0, true); 32 | try{ 33 | // TODO: test for security error thown. 34 | loader.load(url); 35 | }catch( e : SecurityError){ 36 | onSecurityErrorHandler(_createErrorEvent(e)); 37 | 38 | } 39 | }; 40 | 41 | override public function onErrorHandler(evt : ErrorEvent) : void { 42 | super.onErrorHandler(evt); 43 | } 44 | 45 | override public function onStartedHandler(evt : Event) : void{ 46 | super.onStartedHandler(evt); 47 | }; 48 | 49 | override public function onCompleteHandler(evt : Event) : void { 50 | // _content = new ByteArray(loader.data); 51 | _content = evt.target.data; 52 | super.onCompleteHandler(evt); 53 | }; 54 | 55 | override public function stop() : void{ 56 | try{ 57 | if(loader){ 58 | loader.close(); 59 | } 60 | }catch(e : Error){ 61 | 62 | } 63 | super.stop(); 64 | }; 65 | 66 | override public function cleanListeners() : void { 67 | if(loader){ 68 | loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); 69 | loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); 70 | loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); 71 | loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); 72 | loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false); 73 | loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false); 74 | } 75 | } 76 | 77 | override public function destroy() : void{ 78 | stop(); 79 | cleanListeners(); 80 | _content = null; 81 | loader = null; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/loadingtypes/JSONItem.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.loadingtypes { 2 | 3 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 4 | import br.com.stimuli.loading.BulkLoader; 5 | 6 | 7 | import flash.display.*; 8 | import flash.net.*; 9 | import flash.events.*; 10 | import flash.utils.*; 11 | import com.adobe.serialization.json.JSON 12 | /** @private */ 13 | public class JSONItem extends LoadingItem { 14 | 15 | public var loader : URLLoader; 16 | 17 | public function JSONItem(url : URLRequest, type : String, uid : String){ 18 | super(url, type, uid); 19 | } 20 | 21 | override public function _parseOptions(props : Object) : Array{ 22 | return super._parseOptions(props); 23 | } 24 | 25 | override public function load() : void{ 26 | super.load(); 27 | loader = new URLLoader(); 28 | loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); 29 | loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); 30 | loader.addEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false, 0, true); 31 | loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false, 0, true); 32 | loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false, 0, true); 33 | loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); 34 | try{ 35 | // TODO: test for security error thown. 36 | loader.load(url); 37 | }catch( e : SecurityError){ 38 | onSecurityErrorHandler(_createErrorEvent(e)); 39 | 40 | } 41 | }; 42 | 43 | override public function onErrorHandler(evt : ErrorEvent) : void{ 44 | super.onErrorHandler(evt); 45 | } 46 | 47 | override public function onStartedHandler(evt : Event) : void{ 48 | super.onStartedHandler(evt); 49 | }; 50 | 51 | override public function onCompleteHandler(evt : Event) : void { 52 | try{ 53 | _content = JSON.decode(loader.data); 54 | }catch(e : Error){ 55 | _content = null; 56 | status = STATUS_ERROR; 57 | dispatchEvent(_createErrorEvent(e)); 58 | } 59 | super.onCompleteHandler(evt); 60 | }; 61 | 62 | override public function stop() : void{ 63 | try{ 64 | if(loader){ 65 | loader.close(); 66 | } 67 | }catch(e : Error){ 68 | } 69 | super.stop(); 70 | }; 71 | 72 | override public function cleanListeners() : void { 73 | if(loader){ 74 | loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); 75 | loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); 76 | loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); 77 | loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); 78 | loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false); 79 | loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false); 80 | } 81 | } 82 | 83 | override public function isText(): Boolean{ 84 | return true; 85 | } 86 | 87 | override public function destroy() : void{ 88 | stop(); 89 | cleanListeners(); 90 | _content = null; 91 | loader = null; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/loadingtypes/SoundItem.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.loadingtypes { 2 | 3 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 4 | import br.com.stimuli.loading.BulkLoader; 5 | import flash.display.*; 6 | import flash.net.*; 7 | import flash.events.*; 8 | import flash.utils.*; 9 | import flash.media.Sound; 10 | 11 | /** @private */ 12 | public class SoundItem extends LoadingItem { 13 | public var loader : Sound; 14 | 15 | public function SoundItem(url : URLRequest, type : String, uid : String){ 16 | specificAvailableProps = [BulkLoader.CONTEXT]; 17 | super(url, type, uid); 18 | } 19 | 20 | override public function _parseOptions(props : Object) : Array{ 21 | _context = props[BulkLoader.CONTEXT] || null; 22 | 23 | return super._parseOptions(props); 24 | } 25 | 26 | override public function load() : void{ 27 | super.load(); 28 | loader = new Sound(); 29 | loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); 30 | loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); 31 | loader.addEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false, 0, true); 32 | loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); 33 | loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false, 0, true); 34 | try{ 35 | // TODO: test for security error thown. 36 | loader.load(url, _context); 37 | }catch( e : SecurityError){ 38 | onSecurityErrorHandler(_createErrorEvent(e)); 39 | 40 | } 41 | }; 42 | 43 | override public function onStartedHandler(evt : Event) : void{ 44 | _content = loader; 45 | super.onStartedHandler(evt); 46 | }; 47 | 48 | override public function onErrorHandler(evt : ErrorEvent) : void{ 49 | super.onErrorHandler(evt); 50 | } 51 | 52 | override public function onCompleteHandler(evt : Event) : void { 53 | _content = loader 54 | super.onCompleteHandler(evt); 55 | }; 56 | 57 | override public function stop() : void{ 58 | try{ 59 | if(loader){ 60 | loader.close(); 61 | } 62 | }catch(e : Error){ 63 | 64 | } 65 | super.stop(); 66 | }; 67 | 68 | override public function cleanListeners() : void { 69 | if (loader){ 70 | loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); 71 | loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); 72 | loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); 73 | loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); 74 | loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false); 75 | } 76 | 77 | } 78 | 79 | override public function isStreamable(): Boolean{ 80 | return true; 81 | } 82 | 83 | override public function isSound(): Boolean{ 84 | return true; 85 | } 86 | 87 | override public function destroy() : void{ 88 | cleanListeners(); 89 | stop(); 90 | _content = null; 91 | loader = null; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/loadingtypes/URLItem.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.loadingtypes { 2 | 3 | import br.com.stimuli.loading.BulkLoader; 4 | 5 | import flash.display.*; 6 | import flash.events.*; 7 | import flash.net.*; 8 | import flash.utils.*; 9 | /** @private */ 10 | public class URLItem extends LoadingItem { 11 | public var loader : URLLoader; 12 | 13 | public function URLItem(url : URLRequest, type : String, uid : String){ 14 | super(url, type, uid); 15 | } 16 | 17 | override public function _parseOptions(props : Object) : Array{ 18 | return super._parseOptions(props); 19 | } 20 | 21 | override public function load() : void{ 22 | super.load(); 23 | loader = new URLLoader(); 24 | loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); 25 | loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); 26 | loader.addEventListener(IOErrorEvent.IO_ERROR, super.onErrorHandler, false, 0, true); 27 | loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false, 0, true); 28 | loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); 29 | try{ 30 | // TODO: test for security error thown. 31 | loader.load(url); 32 | }catch( e : SecurityError){ 33 | onSecurityErrorHandler(_createErrorEvent(e)); 34 | } 35 | }; 36 | 37 | override public function onStartedHandler(evt : Event) : void{ 38 | super.onStartedHandler(evt); 39 | }; 40 | 41 | override public function onCompleteHandler(evt : Event) : void { 42 | _content = loader.data; 43 | super.onCompleteHandler(evt); 44 | }; 45 | 46 | override public function stop() : void{ 47 | try{ 48 | if(loader){ 49 | loader.close(); 50 | } 51 | }catch(e : Error){ 52 | 53 | } 54 | super.stop(); 55 | }; 56 | 57 | override public function cleanListeners() : void { 58 | if(loader){ 59 | loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); 60 | loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); 61 | loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); 62 | loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); 63 | loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false); 64 | } 65 | 66 | } 67 | 68 | override public function isText(): Boolean{ 69 | return true; 70 | } 71 | 72 | override public function destroy() : void{ 73 | stop(); 74 | cleanListeners(); 75 | _content = null; 76 | loader = null; 77 | } 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/loadingtypes/XMLItem.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.loadingtypes { 2 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import flash.display.*; 5 | import flash.net.*; 6 | import flash.events.*; 7 | import flash.utils.*; 8 | 9 | /** @private */ 10 | public class XMLItem extends LoadingItem { 11 | public var loader : URLLoader; 12 | 13 | public function XMLItem(url : URLRequest, type : String, uid : String){ 14 | super(url, type, uid); 15 | } 16 | 17 | override public function _parseOptions(props : Object) : Array{ 18 | return super._parseOptions(props); 19 | } 20 | 21 | override public function load() : void{ 22 | super.load(); 23 | loader = new URLLoader(); 24 | loader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true); 25 | loader.addEventListener(Event.COMPLETE, onCompleteHandler, false, 0, true); 26 | loader.addEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false, 0, true); 27 | loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false, 0, true); 28 | loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false, 0, true); 29 | loader.addEventListener(Event.OPEN, onStartedHandler, false, 0, true); 30 | try{ 31 | // TODO: test for security error thown. 32 | loader.load(url); 33 | }catch( e : SecurityError){ 34 | onSecurityErrorHandler(_createErrorEvent(e)); 35 | 36 | } 37 | }; 38 | 39 | override public function onErrorHandler(evt : ErrorEvent) : void{ 40 | super.onErrorHandler(evt); 41 | } 42 | 43 | override public function onStartedHandler(evt : Event) : void{ 44 | super.onStartedHandler(evt); 45 | }; 46 | 47 | override public function onCompleteHandler(evt : Event) : void { 48 | try{ 49 | _content = new XML(loader.data); 50 | }catch(e : Error){ 51 | _content = null; 52 | status = STATUS_ERROR; 53 | dispatchEvent(_createErrorEvent(e)); 54 | } 55 | super.onCompleteHandler(evt); 56 | }; 57 | 58 | override public function stop() : void{ 59 | try{ 60 | if(loader){ 61 | loader.close(); 62 | } 63 | }catch(e : Error){ 64 | 65 | } 66 | super.stop(); 67 | }; 68 | 69 | override public function cleanListeners() : void { 70 | if(loader){ 71 | loader.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler, false); 72 | loader.removeEventListener(Event.COMPLETE, onCompleteHandler, false); 73 | loader.removeEventListener(IOErrorEvent.IO_ERROR, onErrorHandler, false); 74 | loader.removeEventListener(BulkLoader.OPEN, onStartedHandler, false); 75 | loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, super.onHttpStatusHandler, false); 76 | loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, super.onSecurityErrorHandler, false); 77 | } 78 | 79 | } 80 | 81 | override public function isText(): Boolean{ 82 | return true; 83 | } 84 | 85 | override public function destroy() : void{ 86 | stop(); 87 | cleanListeners(); 88 | _content = null; 89 | loader = null; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/br/com/stimuli/loading/utils/SmartURL.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.utils { 2 | /** 3 | * A simple data holder to normalize an URI components. 4 | **/ 5 | public class SmartURL { 6 | public var rawString : String; 7 | public var protocol : String; 8 | public var port : int; 9 | public var host : String; 10 | public var path : String; 11 | public var queryString : String; 12 | public var queryObject : Object; 13 | public var queryLength : int = 0; 14 | public var fileName : String; 15 | 16 | public function SmartURL(rawString : String){ 17 | this.rawString = rawString; 18 | var URL_RE : RegExp = /((?P[a-zA-Z]+: \/\/) (?P[^:\/]*) (:(?P\d+))?)? (?P[^?]*)? ((?P.*))? /x; 19 | var match : * = URL_RE.exec(rawString); 20 | if (match){ 21 | protocol = Boolean(match.protocol) ? match.protocol : "http://"; 22 | protocol = protocol.substr(0, protocol.indexOf("://")); 23 | host = match.host || null; 24 | port = match.port ? int(match.port) : 80; 25 | path = match.path; 26 | fileName = path.substring(path.lastIndexOf("/"), path.lastIndexOf(".")); 27 | queryString = match.query; 28 | if (queryString){ 29 | queryObject = {}; 30 | queryString = queryString.substr(1); 31 | var value : String; 32 | var varName : String; 33 | for each (var pair : String in queryString.split("&")){ 34 | varName = pair.split("=")[0]; 35 | value = pair.split("=")[1]; 36 | queryObject[varName] = value; 37 | queryLength ++; 38 | } 39 | } 40 | }else{ 41 | trace("no match") 42 | } 43 | } 44 | 45 | /** If called as toString(true) will output a verbose version of this URL. 46 | **/ 47 | public function toString(...rest) : String{ 48 | if (rest.length > 0 && rest[0] == true){ 49 | return "[URL] rawString :" + rawString + ", protocol: " + protocol + ", port: " + port + ", host: " + host + ", path: " + path + ". queryLength: " + queryLength; 50 | } 51 | return rawString; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /swc/bulk_loader.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/swc/bulk_loader.swc -------------------------------------------------------------------------------- /tests/bin/TestSuite.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BulkLoader TestSuite - ASUnit 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 40 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/bin/TestSuite.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthur-debert/BulkLoader/56c74f4a64b093c09a11ba2f5d984ad58e7c91c5/tests/bin/TestSuite.swf -------------------------------------------------------------------------------- /tests/src/BulkLoaderTestRunner.mxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/AutoIdTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.loading.*; 3 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 4 | 5 | import flash.events.*; 6 | import flash.net.*; 7 | 8 | import br.com.stimuli.kisstest.TestCase; 9 | /**@private*/ 10 | public class AutoIdTest extends TestCase { 11 | public var _bulkLoader:BulkLoader; 12 | private var soundURL : URLRequest ; 13 | 14 | public var subs : Object; 15 | /** 16 | * Constructor 17 | * 18 | * @param testMethod Name of the method to test 19 | */ 20 | public function AutoIdTest(testMethod:String) { 21 | super(testMethod); 22 | name = testMethod; 23 | } 24 | 25 | /** 26 | * Prepare for test, create instance of class that we are testing. 27 | * Invoked by TestCase.runMethod function. 28 | */ 29 | override public function setUp():void { 30 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()); 31 | dispatchEvent( new Event(Event.INIT)); 32 | } 33 | 34 | /** 35 | * Clean up after test, delete instance of class that we were testing. 36 | */ 37 | override public function tearDown():void { 38 | _bulkLoader.clear(); 39 | BulkLoader.removeAllLoaders(); 40 | _bulkLoader = null; 41 | } 42 | 43 | /* ===================================================== */ 44 | /* = Actual testes = */ 45 | /* ===================================================== */ 46 | 47 | 48 | 49 | public function testNoAutoID():void { 50 | // test stuff no no subs are ok 51 | _bulkLoader.allowsAutoIDFromFileName = false; 52 | var item : LoadingItem = _bulkLoader.add("some-url.jpg"); 53 | assertNull(item.id); 54 | } 55 | 56 | public function testAutoWontOverwriteNormalID():void { 57 | // test stuff no no subs are ok 58 | _bulkLoader.allowsAutoIDFromFileName = true; 59 | var item : LoadingItem = _bulkLoader.add("some-url.jpg", {id:"image"}); 60 | assertEquals(item.id, "image"); 61 | } 62 | 63 | public function testFileNameGuessing() : void{ 64 | assertEquals(BulkLoader.getFileName("http:/dsdsd/dsdsd/image"), "image"); 65 | } 66 | 67 | public function testFileNameGuessingWithExtension() : void{ 68 | assertEquals(BulkLoader.getFileName("http:/dsdsd/dsdsd/image.jpg"), "image"); 69 | } 70 | 71 | public function testFileNameGuessingWithExtensionAndQuery() : void{ 72 | assertEquals(BulkLoader.getFileName("http:/dsdsd/dsdsd/image.jpg?dsds=jhdjs"), "image"); 73 | } 74 | 75 | public function testFileNameGuessingWithQuery() : void{ 76 | assertEquals(BulkLoader.getFileName("http:/dsdsd/dsdsd/image?dsds-dsd"), "image"); 77 | } 78 | 79 | public function testFileNameGuessingEndingWithSlash() : void{ 80 | assertEquals(BulkLoader.getFileName("http:/dsdsd/dsdsd/image/"), "image"); 81 | } 82 | 83 | public function testFileNameGuessingRelative() : void{ 84 | assertEquals(BulkLoader.getFileName("image.jpg"), "image"); 85 | } 86 | 87 | public function testFileNameGuessingRelativeWithDash() : void{ 88 | assertEquals(BulkLoader.getFileName("/image.jpg"), "image"); 89 | } 90 | 91 | public function testAutoWorks():void { 92 | // test stuff no no subs are ok 93 | _bulkLoader.allowsAutoIDFromFileName = true; 94 | var item : LoadingItem = _bulkLoader.add("theImage.jpg"); 95 | assertEquals(item.id, "theImage"); 96 | } 97 | 98 | 99 | } 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/BaseAssyncTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.getTimer; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | 11 | import br.com.stimuli.kisstest.TestCase; 12 | /**@private*/ 13 | public class BaseAsyncTest extends TestCase { 14 | var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public function BaseAsyncTest(name) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | // Override the run method and begin the request for remote data 24 | public override function run():void { 25 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), -1, theLogLevel); 26 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/shoes.jpg"; 27 | var badURL : String = "http://www.emptywhite.com/bulkloader-assets/bad-image.jpg" 28 | var theURL : String = goodURL; 29 | if (this.name == 'testIOError'){ 30 | theURL = badURL; 31 | } 32 | 33 | _bulkLoader.add(theURL, {id:"photo"}); 34 | _bulkLoader.get("photo").addEventListener(BulkLoader.ERROR, onIOError); 35 | 36 | 37 | } 38 | 39 | public function onIOError(evt : Event) : void{ 40 | ioError = evt; 41 | // call the on complete manually 42 | completeHandler(evt); 43 | tearDown(); 44 | } 45 | 46 | public function completeHandler(event:Event):void { 47 | super.run(); 48 | } 49 | 50 | 51 | /** This also works as an assertion that event progress will never be NaN 52 | */ 53 | public function progressHandler(event:ProgressEvent):void { 54 | //var evt : * = event as Object; 55 | var current = Math.floor((event as Object).percentLoaded * 100) /100; 56 | var delta : Number = current - lastProgress; 57 | if (current > lastProgress && delta > 0.099){ 58 | lastProgress = current; 59 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 60 | } 61 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 62 | if (isNaN(event[propName]) ){ 63 | trace(propName, "is not a number" ); 64 | assertFalse(isNaN(event[propName])); 65 | } 66 | } 67 | } 68 | 69 | 70 | override public function setUp():void { 71 | 72 | } 73 | 74 | override public function tearDown():void { 75 | _bulkLoader.removeAll(); 76 | } 77 | 78 | public function testIsRunningOnStart() : void{ 79 | _bulkLoader.start(); 80 | assertTrue(_bulkLoader.isRunning); 81 | } 82 | 83 | public function testStartCanChangeConnections():void { 84 | var oldConnectionsNumber : int = _bulkLoader._numConnections; 85 | _bulkLoader.start(2); 86 | assertFalse(oldConnectionsNumber == _bulkLoader._numConnections) 87 | } 88 | 89 | public function testCorrectLogLevel() : void{ 90 | assertEquals(_bulkLoader.logLevel, theLogLevel) 91 | } 92 | 93 | } 94 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/BulkLoaderTestSuite.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestSuite; 3 | import flash.events.*; 4 | import br.com.stimuli.loading.tests.*; 5 | import flash.utils.*; 6 | import flash.media.SoundMixer; 7 | 8 | /**@private*/ 9 | public class BulkLoaderTestSuite extends TestSuite { 10 | public var testClasses : Array = [ 11 | ProgressEventsTest, 12 | URLItemTest, 13 | InstanceRetrivalTestCase, 14 | XMLItemTest, 15 | LoaderItemMovieTest, 16 | LoadNowTest, 17 | AudioContentTest, 18 | VideoContentTest, 19 | HasItemTest, 20 | HostPriorityTest, 21 | LoaderImageItemTest, 22 | GuessTypeTest, 23 | CollectionTestCase, 24 | RemoveAllTest, 25 | RemoveAllSimpleTest, 26 | GetClassDefinitionTest, 27 | TwoItemsWithTheSameURLTest, 28 | OnErrorTest, 29 | ErrorResumeTest, 30 | SmartURLTest, 31 | RemoveFailedItemTest, 32 | OnCompleteTest, 33 | AutoIdTest, 34 | StringSubstituionTest, 35 | LazyJSONLoaderTest, 36 | LazyXMLLoaderTest, 37 | LazyXMLInternalsTest, 38 | LoaderItemAVM1MovieTest, 39 | VideoContentPausedAtStartTestCase, 40 | PauseAllResumeTest, 41 | ClearNowTest, 42 | StartPausedTest, 43 | ReloadTest, 44 | ClearMemoryTest, 45 | ResumeAllTest, 46 | ResumeTest, 47 | BulkStartTest, 48 | RegisterNewTypeTest, 49 | ]; 50 | 51 | public var testsRun : Object = {} ; 52 | public static var LOADING_VERBOSE : Boolean = false; 53 | 54 | 55 | public function BulkLoaderTestSuite() { 56 | super(); 57 | SoundMixer.soundTransform.volume = 0; 58 | testClasses.forEach(function(cl : Class, ...rest):void{addTestCase(cl)}) 59 | for (var prop : String in testsRun){ 60 | //trace(prop.substring(6, prop.length -1) + " (" + testsRun[prop].length + ")", ":"); 61 | for each (var testName : String in testsRun[prop]){ 62 | //trace("\t",testName ); 63 | } 64 | } 65 | } 66 | 67 | public function addTestsFromClass(klass : Class) : void{ 68 | for each (var name : String in describeType(klass).factory.method.@name){ 69 | if (name.substr(0, 4) == "test"){ 70 | addTest(new klass(name)); 71 | if(!testsRun[String(klass)]){ 72 | testsRun[String(klass)] = []; 73 | } 74 | testsRun[String(klass)].push(name); 75 | } 76 | } 77 | } 78 | 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/BulkStartTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.loading.BulkLoader; 3 | import br.com.stimuli.loading.BulkProgressEvent; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.display.*; 7 | import flash.events.*; 8 | import flash.net.*; 9 | 10 | import br.com.stimuli.kisstest.TestCase; 11 | 12 | /**@private*/ 13 | public class BulkStartTest extends TestCase { public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public var theLogLevel : int = 10; 20 | public function BulkStartTest(name: String) : void { 21 | super(name); 22 | this.name = name; 23 | } 24 | // Override the run method and begin the request for remote data 25 | 26 | 27 | public function onIOError(evt : Event) : void{ 28 | ioError = evt; 29 | // call the on complete manually 30 | completeHandler(evt); 31 | //tearDown(); 32 | } 33 | 34 | public function completeHandler(event:Event):void { 35 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 36 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 37 | dispatchEvent(new Event(Event.INIT)); 38 | } 39 | 40 | 41 | /** This also works as an assertion that event progress will never be NaN 42 | */ 43 | public function progressHandler(event:ProgressEvent):void { 44 | //var evt : * = event as Object; 45 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 46 | var delta : Number = current - lastProgress; 47 | if (current > lastProgress && delta > 0.099){ 48 | lastProgress = current; 49 | if (BulkLoaderTestSuite.LOADING_VERBOSE ) trace(current * 100 , "% loaded") ; 50 | } 51 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 52 | if (isNaN(event[propName]) ){ 53 | trace(propName, "is not a number" ); 54 | assertFalse(isNaN(event[propName])); 55 | } 56 | } 57 | } 58 | 59 | 60 | override public function setUp():void { 61 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), -1, theLogLevel); 62 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/shoes.jpg"; 63 | var badURL : String = "http://www.emptywhite.com/bulkloader-assets/bad-image.jpg" 64 | var theURL : String = goodURL; 65 | if (this.name == 'testIOError'){ 66 | theURL = badURL; 67 | } 68 | 69 | _bulkLoader.add(theURL, {id:"photo"}); 70 | _bulkLoader.get("photo").addEventListener(BulkLoader.ERROR, onIOError); 71 | _bulkLoader.addEventListener(Event.COMPLETE, completeHandler); 72 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 73 | //_bulkLoader.start(); 74 | completeHandler(new Event("dummy")) 75 | } 76 | 77 | override public function tearDown():void { 78 | _bulkLoader.clear(); 79 | BulkLoader.removeAllLoaders(); 80 | _bulkLoader = null; 81 | } 82 | 83 | public function testIsRunningOnStart() : void{ 84 | _bulkLoader.start(); 85 | assertTrue(_bulkLoader.isRunning); 86 | } 87 | 88 | public function testStartCanChangeConnections():void { 89 | var oldConnectionsNumber : int = _bulkLoader._numConnections; 90 | _bulkLoader.start(2); 91 | assertFalse(oldConnectionsNumber == _bulkLoader._numConnections) 92 | } 93 | 94 | public function testCorrectLogLevel() : void{ 95 | assertEquals(_bulkLoader.logLevel, theLogLevel) 96 | } 97 | 98 | } 99 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ClearMemoryTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.loading.BulkLoader; 3 | import br.com.stimuli.loading.loadingtypes.*; 4 | 5 | import flash.display.*; 6 | import flash.events.*; 7 | import flash.net.*; 8 | import flash.utils.*; 9 | 10 | import br.com.stimuli.kisstest.TestCase; 11 | /**@private*/ 12 | public class ClearMemoryTest extends TestCase { 13 | public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | 20 | public var timer : Timer 21 | public function ClearMemoryTest(name : String) : void { 22 | super(name); 23 | this.name = name; 24 | } 25 | // Override the run method and begin the request for remote data 26 | public override function setUp():void { 27 | var numCon : int = 1; 28 | if (name == "testLoadAfterRemoveWithStart") numCon = 7; 29 | 30 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), 1) 31 | _bulkLoader.stringSubstitutions = { 32 | "base_path": "http://www.emptywhite.com/bulkloader-assets/" 33 | } 34 | var fileName : String ; 35 | for (var i:int = 1; i<11; i++){ 36 | fileName = "small-" + (i < 10 ? "0" + i : "" + i) + ".jpg"; 37 | 38 | _bulkLoader.add("{base_path}" + fileName, {id:String(i)}); 39 | } 40 | 41 | 42 | _bulkLoader.start(); 43 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 44 | //_bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 45 | 46 | } 47 | 48 | 49 | 50 | public function completeHandler(event:Event):void { 51 | dispatchEvent(new Event(Event.INIT)); 52 | } 53 | 54 | 55 | /** This also works as an assertion that event progress will never be NaN 56 | */ 57 | public function progressHandler(event:ProgressEvent):void { 58 | //var evt : * = event as Object; 59 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 60 | var delta : Number = current - lastProgress; 61 | if (current > lastProgress && delta > 0.099){ 62 | lastProgress = current; 63 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 64 | } 65 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 66 | if (isNaN(event[propName]) ){ 67 | trace(propName, "is not a number" ); 68 | assertFalse(isNaN(event[propName])); 69 | } 70 | } 71 | } 72 | 73 | 74 | 75 | override public function tearDown():void { 76 | _bulkLoader.clear(); 77 | BulkLoader.removeAllLoaders(); 78 | _bulkLoader = null; 79 | } 80 | 81 | public function testItemsLoadedIsValidAfterClearMemory() : void{ 82 | var keys : Array = []; 83 | for each (var item : LoadingItem in _bulkLoader.items){ 84 | _bulkLoader.getContent(item._id, true); 85 | keys.push(item._id); 86 | } 87 | assertEquals(_bulkLoader.itemsLoaded, 0); 88 | 89 | assertEquals(0, _bulkLoader.getProgressForItems(keys).itemsLoaded); 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ClearNowTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.getTimer; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class ClearNowTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public var ioError : Event; 17 | 18 | public function ClearNowTest(name : String) : void { 19 | super(name); 20 | this.name = name; 21 | } 22 | // Override the run method and begin the request for remote data 23 | public override function setUp():void { 24 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 25 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/movie.flv"; 26 | var theURL : String = goodURL; 27 | 28 | _bulkLoader.add(theURL, {id:"bad"}); 29 | 30 | _bulkLoader.start(); 31 | _bulkLoader.removeAll(); 32 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/some-text.txt", {id:"text"}); 33 | _bulkLoader.start(); 34 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 35 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 36 | } 37 | 38 | public function onIOError(evt : Event) : void{ 39 | ioError = evt; 40 | // call the on complete manually 41 | completeHandler(evt); 42 | tearDown(); 43 | } 44 | 45 | public function completeHandler(event:Event):void { 46 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 47 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 48 | dispatchEvent(new Event(Event.INIT)); 49 | } 50 | 51 | 52 | /** This also works as an assertion that event progress will never be NaN 53 | */ 54 | public function progressHandler(event:ProgressEvent):void { 55 | //var evt : * = event as Object; 56 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 57 | var delta : Number = current - lastProgress; 58 | if (current > lastProgress && delta > 0.099){ 59 | lastProgress = current; 60 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 61 | } 62 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 63 | if (isNaN(event[propName]) ){ 64 | trace(propName, "is not a number" ); 65 | assertFalse(isNaN(event[propName])); 66 | } 67 | } 68 | } 69 | 70 | 71 | 72 | override public function tearDown():void { 73 | _bulkLoader.clear(); 74 | BulkLoader.removeAllLoaders(); 75 | _bulkLoader = null; 76 | } 77 | 78 | public function testLoadHasItem():void { 79 | assertNotNull(BulkLoader.whichLoaderHasItem("text")); 80 | } 81 | 82 | public function testClearAllHideKeys():void { 83 | _bulkLoader.clear(); 84 | assertNull(BulkLoader.whichLoaderHasItem("text")); 85 | } 86 | 87 | public function testClearAllThrowsError() : void{ 88 | var theError : Error; 89 | _bulkLoader.clear(); 90 | try{ 91 | _bulkLoader.add("some"); 92 | }catch(e : Error){ 93 | theError = e; 94 | } 95 | assertNotNull(theError); 96 | } 97 | 98 | public function testClearAllIsSafe() : void{ 99 | var theError : Error; 100 | _bulkLoader.clear(); 101 | try{ 102 | _bulkLoader.clear() 103 | }catch(e : Error){ 104 | theError = e; 105 | } 106 | assertNull(theError); 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ErrorResumeTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.events.*; 7 | import flash.media.Sound; 8 | /**@private*/ 9 | public class ErrorResumeTest extends TestCase { public var _bulkLoader : BulkLoader; 10 | public var lastProgress : Number = 0; 11 | public var sound : Sound; 12 | public var sound1 : Sound; 13 | public var itemsToTest : int = 6; 14 | public var ioError : Event; 15 | public var errorsFired : int = 0; 16 | public function ErrorResumeTest(name : String) : void { 17 | super(name); 18 | this.name = name; 19 | } 20 | // Override the run method and begin the request for remote data 21 | public override function setUp():void { 22 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), 2 /*, BulkLoader.LOG_INFO*/); 23 | var startURL : String = "http://www.emptywhite.com/bulkloader-assets/small-0"; 24 | var item : LoadingItem; 25 | for (var i : int = 1 ; i < itemsToTest ; i ++){ 26 | item = _bulkLoader.add(startURL + String(i) + ".jpg", {id:i}); 27 | item.addEventListener(Event.COMPLETE, onItemLoaded, false, 0, true); 28 | if (i == 4){ 29 | // add a broken link to check if erros won't jam the loader 30 | _bulkLoader.add(startURL + "sdsdsds0.jpg", {id:"baditem"}); 31 | _bulkLoader.add(startURL + "sdsdsds1.jpg", {id:"baditem2"}); 32 | _bulkLoader.add(startURL + "sdsdsds2.jpg", {id:"baditem3"}); 33 | } 34 | 35 | } 36 | 37 | _bulkLoader.addEventListener(BulkLoader.ERROR, onIOError); 38 | _bulkLoader.start(); 39 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 40 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 41 | } 42 | 43 | public function onIOError(evt : Event) : void{ 44 | errorsFired ++; 45 | ioError = evt; 46 | // call the on complete manually 47 | //trace(_bulkLoader.itemsLoaded , errorsFired, _bulkLoader.itemsTotal); 48 | if (_bulkLoader.itemsLoaded + errorsFired >= _bulkLoader.itemsTotal -1){ 49 | completeHandler(evt); 50 | } 51 | } 52 | 53 | public function onItemLoaded(evt : Event) : void{ 54 | // check if errors + loaded items are complete: 55 | //trace(_bulkLoader.itemsLoaded , errorsFired, _bulkLoader.itemsTotal); 56 | if (_bulkLoader.itemsLoaded + errorsFired >= _bulkLoader.itemsTotal -1){ 57 | completeHandler(evt); 58 | } 59 | } 60 | 61 | public function completeHandler(event:Event):void { 62 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 63 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 64 | dispatchEvent(new Event(Event.INIT)); 65 | } 66 | 67 | /** This also works as an assertion that event progress will never be NaN 68 | */ 69 | public function progressHandler(event:ProgressEvent):void { 70 | //var evt : * = event as Object; 71 | var current : Number = Math.floor((event as Object).percentLoaded * 100) /100; 72 | if (current > lastProgress){ 73 | lastProgress = current; 74 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 75 | } 76 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 77 | if (isNaN(event[propName]) ){ 78 | trace(propName, "is not a number" ); 79 | assertFalse(isNaN(event[propName])); 80 | } 81 | } 82 | //trace("event", (event as Object).percentLoaded, current); 83 | } 84 | 85 | 86 | 87 | override public function tearDown():void { 88 | // destroy the class under test instance 89 | _bulkLoader.clear(); 90 | BulkLoader.removeAllLoaders(); 91 | _bulkLoader = null; 92 | } 93 | 94 | 95 | public function testAllItemsDoneLoaded() : void{ 96 | for (var i : int = 1 ; i < itemsToTest ; i ++){ 97 | assertNotNull(_bulkLoader.getBitmap(String(i))); 98 | } 99 | assertNull(_bulkLoader.get("baditem").content); 100 | } 101 | 102 | } 103 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/GetClassDefinitionTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.loading.*; 3 | import br.com.stimuli.loading.loadingtypes.*; 4 | 5 | import flash.display.*; 6 | import flash.events.*; 7 | import flash.net.*; 8 | import flash.system.LoaderContext; 9 | import flash.system.ApplicationDomain; 10 | import br.com.stimuli.kisstest.TestCase; 11 | /**@private*/ 12 | public class GetClassDefinitionTest extends TestCase { 13 | public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public var theImageItem : ImageItem; 20 | public var content : *; 21 | public var contentIsBitmap : Boolean; 22 | 23 | 24 | // 25 | public var theCompleteEvent : Event; 26 | 27 | public function GetClassDefinitionTest(name: String) : void { 28 | super(name); 29 | this.name = name; 30 | } 31 | // Override the run method and begin the request for remote data 32 | public override function setUp():void { 33 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 34 | _bulkLoader.start(); 35 | var ctx : LoaderContext; 36 | if (name == "testSameContextClassDefinition"){ 37 | ctx = new LoaderContext(); 38 | ctx.applicationDomain = ApplicationDomain.currentDomain; 39 | trace("same contexts"); 40 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/CompiledClassTest.swf", {"context":ctx, "id": "compiled-swf"}); 41 | }else{ 42 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/CompiledClassTest.swf", {"id": "compiled-swf"}); 43 | trace("different contexts") 44 | } 45 | 46 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandlerSpecialEvent); 47 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 48 | } 49 | 50 | public function onIOError(evt : Event) : void{ 51 | ioError = evt; 52 | // call the on complete manually 53 | completeHandlerSpecialEvent(); 54 | // tearDown(); 55 | } 56 | 57 | public function onImageComplete(event : Event) : void{ 58 | content = event.target.content; 59 | contentIsBitmap = event.target.content is Bitmap; 60 | theCompleteEvent = event; 61 | } 62 | protected function completeHandlerSpecialEvent(event:BulkProgressEvent=null):void { 63 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandlerSpecialEvent); 64 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 65 | var e : Event= new Event(Event.INIT); 66 | dispatchEvent(e); 67 | } 68 | 69 | 70 | /** This also works as an assertion that event progress will never be NaN 71 | */ 72 | public function progressHandler(event:ProgressEvent):void { 73 | //var evt : * = event as Object; 74 | var current : Number= Math.floor((event as Object).percentLoaded * 100) /100; 75 | var delta : Number = current - lastProgress; 76 | if (current > lastProgress && delta > 0.099){ 77 | lastProgress = current; 78 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 79 | } 80 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 81 | if (isNaN(event[propName]) ){ 82 | trace(propName, "is not a number" ); 83 | assertFalse(isNaN(event[propName])); 84 | } 85 | } 86 | } 87 | 88 | 89 | 90 | 91 | override public function tearDown():void { 92 | _bulkLoader.clear(); 93 | BulkLoader.removeAllLoaders(); 94 | _bulkLoader = null; 95 | } 96 | 97 | // public function testSameContextClassDefinition():void { 98 | // trace("should be true", (_bulkLoader.get("compiled-swf") as ImageItem).loader.contentLoaderInfo.applicationDomain == ApplicationDomain.currentDomain); 99 | // assertNotNull(_bulkLoader.getClassByName("CompiledClass")); 100 | // } 101 | 102 | public function testLoadinItemGetDefinition() : void{ 103 | assertNotNull((_bulkLoader.get("compiled-swf") as ImageItem).getDefinitionByName("CompiledClass")); 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/HasItemTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.*; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class HasItemTest extends TestCase { 12 | 13 | public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public var dispatchedProgressAfterComplete : Boolean = false; 20 | public var numHasItems : int = 0; 21 | public var timer : Timer; 22 | public function HasItemTest(name : String) : void { 23 | super(name); 24 | this.name = name; 25 | } 26 | public var items :Array = [ 27 | "http://www.emptywhite.com/bulkloader-assets/some-text.txt", 28 | "http://www.emptywhite.com/bulkloader-assets/movie.flv" , 29 | "http://www.emptywhite.com/bulkloader-assets/samplexml.xml", 30 | "http://www.emptywhite.com/bulkloader-assets/shoes.jpg", 31 | "http://www.emptywhite.com/bulkloader-assets/chopin.mp3" 32 | ] 33 | // Override the run method and begin the request for remote data 34 | public override function setUp():void { 35 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 36 | for each(var url : String in items){_bulkLoader.add(url, {"preventCache":true});} 37 | _bulkLoader.start(); 38 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 39 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 40 | for each(url in items){ 41 | if (_bulkLoader.hasItem(url)) numHasItems ++; 42 | } 43 | } 44 | 45 | public function onIOError(evt : Event) : void{ 46 | ioError = evt; 47 | // call the on complete manually 48 | completeHandler(evt); 49 | tearDown(); 50 | } 51 | 52 | public function completeHandler(event:Event):void { 53 | timer = new Timer(2000, 1); 54 | timer.addEventListener( TimerEvent.TIMER_COMPLETE, runWrapper) 55 | timer.start(); 56 | } 57 | 58 | public function runWrapper(evt : Event) : void{ 59 | dispatchEvent(new Event(Event.INIT)); 60 | } 61 | 62 | /** This also works as an assertion that event progress will never be NaN 63 | */ 64 | public function progressHandler(event:ProgressEvent):void { 65 | //var evt : * = event as Object; 66 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 67 | var delta : Number = current - lastProgress; 68 | if (current > lastProgress && delta > 0.099){ 69 | lastProgress = current; 70 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 71 | } 72 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 73 | if (isNaN(event[propName]) ){ 74 | trace(propName, "is not a number" ); 75 | assertFalse(isNaN(event[propName])); 76 | } 77 | } 78 | } 79 | 80 | 81 | 82 | override public function tearDown():void { 83 | _bulkLoader.clear(); 84 | BulkLoader.removeAllLoaders(); 85 | _bulkLoader = null; 86 | } 87 | 88 | public function testHasItemsIsFalseAtStart():void { 89 | assertEquals(numHasItems, 0); 90 | } 91 | 92 | 93 | public function testHasItemsIsTrueOnLoad() : void{ 94 | numHasItems = 0; 95 | for each(var url :String in items){ 96 | if (_bulkLoader.hasItem(url)) numHasItems ++; 97 | } 98 | assertEquals(numHasItems, items.length); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/LazyXMLInternalsTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.getTimer; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | import br.com.stimuli.loading.lazyloaders.*; 11 | /**@private*/ 12 | public class LazyXMLInternalsTest extends TestCase { 13 | public var lazyLoader : LazyXMLLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public function LazyXMLInternalsTest(name : String) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | // Override the run method and begin the request for remote data 24 | public override function setUp():void { 25 | lazyLoader = new LazyXMLLoader("http://www.emptywhite.com/bulkloader-assets/lazyloader.xml", BulkLoader.getUniqueName()); 26 | lazyLoader.addEventListener("complete", completeHandler); 27 | lazyLoader.addEventListener("progress", progressHandler); 28 | lazyLoader.start(); 29 | } 30 | 31 | public function onIOError(evt : Event) : void{ 32 | ioError = evt; 33 | // call the on complete manually 34 | completeHandler(evt); 35 | tearDown(); 36 | } 37 | 38 | public function completeHandler(event:Event):void { 39 | lazyLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 40 | 41 | dispatchEvent(new Event(Event.INIT)); 42 | } 43 | 44 | 45 | /** This also works as an assertion that event progress will never be NaN 46 | */ 47 | public function progressHandler(event:ProgressEvent):void { 48 | var percentLoaded : Number = event.bytesLoaded/ event.bytesTotal; 49 | var current :Number = Math.floor(percentLoaded * 100) /100; 50 | var delta : Number = current - lastProgress; 51 | if (current > lastProgress && delta > 0.099){ 52 | lastProgress = current; 53 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 54 | } 55 | 56 | } 57 | 58 | 59 | 60 | 61 | override public function tearDown():void { 62 | lazyLoader.clear(); 63 | lazyLoader.removeAll(); 64 | BulkLoader.removeAllLoaders(); 65 | lazyLoader = null; 66 | } 67 | 68 | public function testXMLLoaded() : void{ 69 | assertNotNull(lazyLoader); 70 | } 71 | 72 | public function testProgressNotNull() : void{ 73 | assertTrue(lastProgress > 0.1) 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/LoadNowTest.as: -------------------------------------------------------------------------------- 1 | /* AS3 2 | Copyright 2008 __MyCompanyName__. 3 | */ 4 | package br.com.stimuli.loading.tests { 5 | import br.com.stimuli.kisstest.TestCase; 6 | import br.com.stimuli.loading.*; 7 | import br.com.stimuli.loading.loadingtypes.LoadingItem; 8 | import flash.net.*; 9 | import flash.events.*; 10 | /**@private*/ 11 | public class LoadNowTest extends TestCase { 12 | public var _bulkLoader:BulkLoader; 13 | private var soundURL : URLRequest ; 14 | 15 | /** 16 | * Constructor 17 | * 18 | * @param testMethod Name of the method to test 19 | */ 20 | public function LoadNowTest(testMethod:String) { 21 | super(testMethod); 22 | name = testMethod; 23 | } 24 | 25 | /** 26 | * Prepare for test, create instance of class that we are testing. 27 | * Invoked by TestCase.runMethod function. 28 | */ 29 | override public function setUp():void { 30 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), 1); 31 | soundURL = new URLRequest("http://www.emptywhite.com/bulkloader-assets/chopin.mp3"); 32 | _bulkLoader.add(soundURL, {id:"the-sound", priority:100, preventCache:true}); 33 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/movie.flv", {id:"the-movie", pausedAtStart:true, priority:200, preventCache:true}); 34 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/some-text.txt", {id:"text", preventCache:true}); 35 | _bulkLoader.start(); 36 | // make sure loadNow wont fail before items are loaded: 37 | _bulkLoader.loadNow("the-movie"); 38 | dispatchEvent(new Event(Event.INIT)); 39 | } 40 | 41 | /** 42 | * Clean up after test, delete instance of class that we were testing. 43 | */ 44 | override public function tearDown():void { 45 | _bulkLoader.clear(); 46 | BulkLoader.removeAllLoaders(); 47 | _bulkLoader = null; 48 | } 49 | 50 | /* ===================================================== */ 51 | /* = Actual testes = */ 52 | /* ===================================================== */ 53 | 54 | 55 | public function testLoadNow():void { 56 | var item : LoadingItem = _bulkLoader.get("text"); 57 | var status : String = item.status 58 | assertTrue(item.status == null); 59 | assertFalse(item._isLoading); 60 | // now force load 61 | _bulkLoader.loadNow("text"); 62 | assertEquals(_bulkLoader._getAllConnections().indexOf(item) , 0); 63 | 64 | assertTrue(item._isLoading); 65 | } 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/LoaderItemAVM1MovieTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.display.*; 7 | import flash.events.*; 8 | import flash.net.*; 9 | 10 | /**@private*/ 11 | public class LoaderItemAVM1MovieTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public function LoaderItemAVM1MovieTest(name : String) : void { 17 | super(name); 18 | this.name = name; 19 | } 20 | // Override the run method and begin the request for remote data 21 | public override function setUp():void { 22 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 23 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/avm1movie.swf", {id:"avm1movie"}); 24 | 25 | 26 | _bulkLoader.start(); 27 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 28 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 29 | } 30 | 31 | public function completeHandler(event:Event):void { 32 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 33 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 34 | dispatchEvent(new Event(Event.INIT)); 35 | } 36 | 37 | 38 | /** This also works as an assertion that event progress will never be NaN 39 | */ 40 | public function progressHandler(event:ProgressEvent):void { 41 | //var evt : * = event as Object; 42 | var current :Number= Math.floor((event as Object).percentLoaded * 100) /100; 43 | var delta : Number = current - lastProgress; 44 | if (current > lastProgress && delta > 0.099){ 45 | lastProgress = current; 46 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 47 | } 48 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 49 | if (isNaN(event[propName]) ){ 50 | trace(propName, "is not a number" ); 51 | assertFalse(isNaN(event[propName])); 52 | } 53 | } 54 | } 55 | 56 | 57 | 58 | 59 | override public function tearDown():void { 60 | _bulkLoader.clear(); 61 | BulkLoader.removeAllLoaders(); 62 | _bulkLoader = null; 63 | } 64 | 65 | public function testGetAVM1Movie():void { 66 | var item : AVM1Movie = _bulkLoader.getAVM1Movie("avm1movie"); 67 | assertNotNull(item); 68 | } 69 | 70 | public function testIsAVM1Movie() : void{ 71 | var item : * = _bulkLoader.getContent("avm1movie"); 72 | assertTrue(item is AVM1Movie); 73 | } 74 | 75 | public function testHasAlpha() : void{ 76 | var item : AVM1Movie = _bulkLoader.getAVM1Movie("avm1movie"); 77 | assertTrue(item.alpha is Number); 78 | } 79 | 80 | public function testItemIsLoaded() : void{ 81 | assertTrue(_bulkLoader.get("avm1movie")._isLoaded) 82 | } 83 | 84 | 85 | 86 | } 87 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/LoaderItemMovieTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.*; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.display.*; 7 | import flash.events.*; 8 | import flash.net.*; 9 | import flash.utils.getTimer; 10 | 11 | /**@private*/ 12 | public class LoaderItemMovieTest extends TestCase { 13 | public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | public var initTime : int = -1; 16 | public var completeTime : int = -1; 17 | 18 | public var isStreamable : Boolean = true; 19 | 20 | public function LoaderItemMovieTest(name : String) : void { 21 | super(name); 22 | this.name = name; 23 | } 24 | // Override the run method and begin the request for remote data 25 | public override function setUp():void { 26 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 27 | var item : ImageItem = _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/avm2-movie.swf", {id:"avm2movie"}) as ImageItem; 28 | item.addEventListener(Event.INIT, onInit, false, 0, true); 29 | _bulkLoader.start(); 30 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandlerBP); 31 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 32 | } 33 | 34 | public function onInit(evt : Event) : void{ 35 | initTime = getTimer(); 36 | isStreamable = evt.target.isStreamable; 37 | } 38 | 39 | protected function completeHandlerBP(event:BulkProgressEvent):void { 40 | completeTime = getTimer(); 41 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandlerBP); 42 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 43 | dispatchEvent(new Event(Event.INIT)); 44 | } 45 | 46 | 47 | /** This also works as an assertion that event progress will never be NaN 48 | */ 49 | public function progressHandler(event:ProgressEvent):void { 50 | //var evt : * = event as Object; 51 | var current :Number= Math.floor((event as Object).percentLoaded * 100) /100; 52 | var delta : Number = current - lastProgress; 53 | if (current > lastProgress && delta > 0.099){ 54 | lastProgress = current; 55 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 56 | } 57 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 58 | if (isNaN(event[propName]) ){ 59 | trace(propName, "is not a number" ); 60 | assertFalse(isNaN(event[propName])); 61 | } 62 | } 63 | } 64 | 65 | 66 | 67 | 68 | override public function tearDown():void { 69 | _bulkLoader.clear(); 70 | _bulkLoader.removeAll(); 71 | } 72 | 73 | public function testGetavm2movie():void { 74 | var item : MovieClip = _bulkLoader.getMovieClip("avm2movie"); 75 | assertNotNull(item); 76 | } 77 | 78 | public function testIsavm2movie() : void{ 79 | var item : * = _bulkLoader.getContent("avm2movie"); 80 | assertTrue(item is MovieClip); 81 | } 82 | 83 | public function testIsSWF() : void{ 84 | var item : * = _bulkLoader.get("avm2movie"); 85 | assertTrue(item.isSWF()); 86 | } 87 | 88 | public function testHasAlpha() : void{ 89 | var item : MovieClip = _bulkLoader.getMovieClip("avm2movie"); 90 | assertTrue(item.alpha is Number); 91 | } 92 | 93 | public function testItemIsLoaded() : void{ 94 | assertTrue(_bulkLoader.get("avm2movie")._isLoaded) 95 | } 96 | 97 | public function testInitFired() : void{ 98 | assertTrue(initTime > 0); 99 | assertTrue(initTime <= completeTime); 100 | assertTrue(isStreamable); 101 | } 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/OnCompleteTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.*; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class OnCompleteTest extends TestCase { public var _bulkLoader : BulkLoader; 12 | public var lastProgress : Number = 0; 13 | 14 | 15 | public var ioError : Event; 16 | 17 | public var dispatchedProgressAfterComplete : Boolean = false; 18 | public var numOfDispatches : int = 0; 19 | public var hasCompleted : Boolean ; 20 | 21 | public var timer: Timer; 22 | public function OnCompleteTest(name : String) : void { 23 | super(name); 24 | this.name = name; 25 | } 26 | // Override the run method and begin the request for remote data 27 | public override function setUp():void { 28 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 29 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/some-text.txt"; 30 | var preventCache : Boolean = false 31 | if (this.name == 'testWihNoCache'){ 32 | preventCache = true; 33 | } 34 | 35 | _bulkLoader.add(goodURL, {id:"text", preventCache: preventCache}); 36 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/samplexml.xml", {id:"xml", preventCache: preventCache}); 37 | _bulkLoader.get("text").addEventListener(BulkLoader.ERROR, onIOError); 38 | 39 | _bulkLoader.start(); 40 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 41 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 42 | } 43 | 44 | public function onIOError(evt : Event) : void{ 45 | ioError = evt; 46 | // call the on complete manually 47 | completeHandler(evt); 48 | tearDown(); 49 | } 50 | 51 | public function completeHandler(event:Event):void { 52 | numOfDispatches ++; 53 | hasCompleted = true; 54 | timer = new Timer(2000, 1); 55 | timer.addEventListener( TimerEvent.TIMER_COMPLETE, runWrapper) 56 | timer.start(); 57 | } 58 | 59 | public function runWrapper(evt : Event) : void{ 60 | dispatchEvent(new Event(Event.INIT)); 61 | } 62 | 63 | /** This also works as an assertion that event progress will never be NaN 64 | */ 65 | public function progressHandler(event:ProgressEvent):void { 66 | //var evt : * = event as Object; 67 | if(hasCompleted){ 68 | dispatchedProgressAfterComplete = true; 69 | } 70 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 71 | var delta : Number = current - lastProgress; 72 | if (current > lastProgress && delta > 0.099){ 73 | lastProgress = current; 74 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 75 | } 76 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 77 | if (isNaN(event[propName]) ){ 78 | trace(propName, "is not a number" ); 79 | assertFalse(isNaN(event[propName])); 80 | } 81 | } 82 | } 83 | 84 | 85 | 86 | override public function tearDown():void { 87 | _bulkLoader.clear(); 88 | BulkLoader.removeAllLoaders(); 89 | _bulkLoader = null; 90 | } 91 | 92 | public function testOnCompleteFiredOnlyOnce():void { 93 | 94 | assertEquals(numOfDispatches,1); 95 | } 96 | 97 | 98 | public function testItemIsLoaded() : void{ 99 | assertFalse(dispatchedProgressAfterComplete) 100 | } 101 | 102 | public function testWihNoCache() : void{ 103 | assertFalse(dispatchedProgressAfterComplete); 104 | assertEquals(numOfDispatches,1); 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/OnErrorTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.display.*; 7 | import flash.events.*; 8 | import flash.net.*; 9 | import flash.utils.*; 10 | /**@private*/ 11 | public class OnErrorTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public var errorEvent : Event; 17 | 18 | 19 | public function OnErrorTest(name : String) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | // Override the run method and begin the request for remote data 24 | public override function setUp():void { 25 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 26 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/some-text.txt"; 27 | 28 | _bulkLoader.add(goodURL, {id:"200Item", preventCache: true}); 29 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/404file.xml", {id:"404Item",preventCache: true}).addEventListener(BulkLoader.COMPLETE, onGoodURLLoaded, false, 0, true); 30 | 31 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 32 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 33 | _bulkLoader.addEventListener(BulkLoader.ERROR, onError); 34 | _bulkLoader.start(); 35 | } 36 | 37 | public function onError(evt : Event) : void{ 38 | errorEvent = evt ; 39 | //trace("****", evt.target, "current", evt.currentTarget); 40 | // call the on complete manually 41 | if (_bulkLoader.get("200Item").status == LoadingItem.STATUS_FINISHED){ 42 | completeHandler(evt); 43 | 44 | } 45 | 46 | } 47 | 48 | public function onGoodURLLoaded(evt : Event): void{ 49 | if (errorEvent){ 50 | completeHandler(evt); 51 | 52 | } 53 | } 54 | public function completeHandler(event:Event):void { 55 | //super.run(); 56 | dispatchEvent(new Event(Event.INIT)); 57 | } 58 | 59 | 60 | /** This also works as an assertion that event progress will never be NaN 61 | */ 62 | public function progressHandler(event:ProgressEvent):void { 63 | } 64 | 65 | 66 | 67 | override public function tearDown():void { 68 | _bulkLoader.clear(); 69 | BulkLoader.removeAllLoaders(); 70 | _bulkLoader = null; 71 | } 72 | 73 | 74 | 75 | public function testItemIsLoaded() : void{ 76 | assertNotNull(_bulkLoader.get("200Item")) 77 | } 78 | 79 | 80 | public function testHasErrorDispatched() : void{ 81 | assertNotNull(errorEvent); 82 | } 83 | 84 | public function testErrorType() : void{ 85 | assertTrue(errorEvent is ErrorEvent); 86 | } 87 | 88 | public function assertErrorEventTarget() : void{ 89 | 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/RegisterNewTypeTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.events.*; 7 | /**@private*/ 8 | public class RegisterNewTypeTest extends TestCase { public var _bulkLoader : BulkLoader; 9 | public var lastProgress : Number = 0; 10 | 11 | public var registerSuccess : Boolean = false; 12 | public var ioError : Event; 13 | 14 | public function RegisterNewTypeTest(name : String) : void { 15 | super(name); 16 | this.name = name; 17 | } 18 | // Override the run method and begin the request for remote data 19 | public override function setUp():void { 20 | registerSuccess = BulkLoader.registerNewType( "json", "JSON", JSONItem) ; 21 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()); 22 | var item : LoadingItem = _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/lazyloader.json", {id:"json"}); 23 | _bulkLoader.add( "http://www.emptywhite.com/bulkloader-assets/some-text.txt", {"id":"text"}); 24 | // should be able to find the item if type is set as lowe: 25 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/lazyloader.json?fdf", {id:"json2", type:"json"}); 26 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/lazyloader.json?fdf", {id:"json3", type:"JSON"}); 27 | _bulkLoader.addEventListener(BulkLoader.ERROR, onIOError); 28 | 29 | _bulkLoader.start(); 30 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 31 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 32 | } 33 | 34 | public function onIOError(evt : Event) : void{ 35 | ioError = evt; 36 | // call the on complete manually 37 | completeHandler(evt); 38 | } 39 | 40 | public function completeHandler(event:Event):void { 41 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 42 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 43 | dispatchEvent(new Event(Event.INIT)); 44 | } 45 | 46 | /** This also works as an assertion that event progress will never be NaN 47 | */ 48 | public function progressHandler(event:ProgressEvent):void { 49 | //var evt : * = event as Object; 50 | var current : Number = Math.floor((event as Object).percentLoaded * 100) /100; 51 | if (current > lastProgress){ 52 | lastProgress = current; 53 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 54 | } 55 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 56 | if (isNaN(event[propName]) ){ 57 | trace(propName, "is not a number" ); 58 | assertFalse(isNaN(event[propName])); 59 | } 60 | } 61 | //trace("event", (event as Object).percentLoaded, current); 62 | } 63 | 64 | public function testJSONContent () : void{ 65 | var cont : Object = _bulkLoader.getContent("json"); 66 | assertEquals(cont.name, "lazyTest"); 67 | } 68 | 69 | public function testOtherItemType () : void{ 70 | var li : LoadingItem = _bulkLoader.get("text"); 71 | assertTrue(li is URLItem); 72 | } 73 | 74 | public function testNewType () : void{ 75 | var li : LoadingItem = _bulkLoader.get("json"); 76 | assertTrue(li is JSONItem); 77 | } 78 | 79 | public function testNewTypeMixedCased() : void{ 80 | var li : LoadingItem = _bulkLoader.get("json2"); 81 | assertTrue(li is JSONItem); 82 | li = _bulkLoader.get("json3"); 83 | assertTrue(li is JSONItem); 84 | } 85 | 86 | public function testMultipleAdds() : void { 87 | var success : Boolean = BulkLoader.registerNewType( "json", "JSON", JSONItem) ; 88 | assertFalse(success); 89 | } 90 | 91 | 92 | override public function tearDown():void { 93 | // destroy the class under test instance 94 | _bulkLoader.clear(); 95 | BulkLoader.removeAllLoaders(); 96 | _bulkLoader = null; 97 | } 98 | 99 | 100 | } 101 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ReloadTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.getTimer; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class ReloadTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public var ioError : Event; 17 | 18 | public var firstLoaded : Boolean 19 | public var firstLoadedXML : XML; 20 | 21 | public function ReloadTest(name : String) : void { 22 | super(name); 23 | this.name = name; 24 | } 25 | // Override the run method and begin the request for remote data 26 | public override function setUp():void { 27 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 28 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/samplexml.xml"; 29 | 30 | _bulkLoader.add(goodURL, {id:"xml"}); 31 | _bulkLoader.get("xml").addEventListener(BulkLoader.ERROR, onIOError); 32 | 33 | _bulkLoader.start(); 34 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 35 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 36 | } 37 | 38 | public function onIOError(evt : Event) : void{ 39 | ioError = evt; 40 | // call the on complete manually 41 | completeHandler(evt); 42 | tearDown(); 43 | } 44 | 45 | public function completeHandler(event:Event):void { 46 | if (firstLoaded){ 47 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 48 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 49 | dispatchEvent(new Event(Event.INIT)); 50 | return; 51 | } 52 | firstLoaded = true; 53 | firstLoadedXML = _bulkLoader.getXML("xml"); 54 | _bulkLoader.reload("xml"); 55 | } 56 | 57 | 58 | /** This also works as an assertion that event progress will never be NaN 59 | */ 60 | public function progressHandler(event:ProgressEvent):void { 61 | //var evt : * = event as Object; 62 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 63 | var delta : Number = current - lastProgress; 64 | if (current > lastProgress && delta > 0.099){ 65 | lastProgress = current; 66 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 67 | } 68 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 69 | if (isNaN(event[propName]) ){ 70 | trace(propName, "is not a number" ); 71 | assertFalse(isNaN(event[propName])); 72 | } 73 | } 74 | } 75 | 76 | 77 | 78 | override public function tearDown():void { 79 | _bulkLoader.clear(); 80 | BulkLoader.removeAllLoaders(); 81 | _bulkLoader = null; 82 | } 83 | 84 | public function testReloadedContents():void { 85 | 86 | assertTrue(firstLoaded); 87 | assertTrue(firstLoadedXML); 88 | var secondXML : XML = _bulkLoader.getXML("xml"); 89 | assertEquals(firstLoadedXML.toString(), secondXML.toString()); 90 | assertFalse(firstLoadedXML === secondXML) 91 | 92 | } 93 | 94 | public function testReloadKeepsItemCount() : void{ 95 | assertEquals(_bulkLoader.items.length, 1); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/RemoveAllSimpleTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.BulkProgressEvent; 5 | import br.com.stimuli.loading.loadingtypes.*; 6 | 7 | import flash.display.*; 8 | import flash.events.*; 9 | import flash.net.*; 10 | import flash.utils.*; 11 | /**@private*/ 12 | public class RemoveAllSimpleTest extends TestCase { 13 | public var _bulkLoader : BulkLoader; 14 | public var lastProgress : Number = 0; 15 | 16 | 17 | public var ioError : Event; 18 | 19 | public function RemoveAllSimpleTest(name : String) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | // Override the run method and begin the request for remote data 24 | public override function setUp():void { 25 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName(), 1, BulkLoader.LOG_VERBOSE) 26 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/small-01.jpg", {id:String("small_1")}); 27 | _bulkLoader.start(); 28 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 29 | //_bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 30 | } 31 | 32 | 33 | 34 | public function onIOError(evt : Event) : void{ 35 | ioError = evt; 36 | // call the on complete manually 37 | completeHandler(evt); 38 | tearDown(); 39 | } 40 | 41 | public function completeHandler(event:Event):void { 42 | 43 | dispatchEvent(new Event(Event.INIT)); 44 | } 45 | 46 | 47 | /** This also works as an assertion that event progress will never be NaN 48 | */ 49 | public function progressHandler(event:ProgressEvent):void { 50 | //var evt : * = event as Object; 51 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 52 | var delta : Number = current - lastProgress; 53 | if (current > lastProgress && delta > 0.099){ 54 | lastProgress = current; 55 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 56 | } 57 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 58 | if (isNaN(event[propName]) ){ 59 | trace(propName, "is not a number" ); 60 | assertFalse(isNaN(event[propName])); 61 | } 62 | } 63 | } 64 | 65 | 66 | 67 | override public function tearDown():void { 68 | _bulkLoader.clear(); 69 | BulkLoader.removeAllLoaders(); 70 | _bulkLoader = null; 71 | } 72 | 73 | 74 | public function testItemsLoaded() : void{ 75 | assertEquals(_bulkLoader.itemsLoaded, 1); 76 | _bulkLoader.removeAll(); 77 | assertEquals(_bulkLoader.itemsLoaded, 0); 78 | } 79 | 80 | public function testItemsTotal() : void{ 81 | assertEquals(_bulkLoader.itemsTotal, 1); 82 | _bulkLoader.removeAll(); 83 | assertEquals(_bulkLoader.itemsTotal, 0); 84 | } 85 | 86 | public function testTotalWeight() : void{ 87 | assertEquals(_bulkLoader.totalWeight, 1); 88 | _bulkLoader.removeAll(); 89 | assertEquals(_bulkLoader.totalWeight, 0); 90 | } 91 | 92 | public function testProgress() : void{ 93 | var p : BulkProgressEvent = _bulkLoader.getProgressForItems(["small_1"]); 94 | assertEquals(p.itemsLoaded, 1); 95 | assertEquals(p.itemsTotal, 1); 96 | assertEquals(p._percentLoaded, 1); 97 | assertEquals(p.ratioLoaded, 1); 98 | assertEquals(p.weightPercent, 1); 99 | _bulkLoader.removeAll(); 100 | assertEquals(_bulkLoader.itemsLoaded, 0); 101 | assertEquals(_bulkLoader.itemsTotal, 0); 102 | assertEquals(_bulkLoader._percentLoaded, 0); 103 | 104 | 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/RemoveFailedItemTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.loading.*; 3 | import br.com.stimuli.loading.loadingtypes.*; 4 | 5 | import flash.display.*; 6 | import flash.events.*; 7 | import flash.net.*; 8 | 9 | import br.com.stimuli.kisstest.TestCase; 10 | /**@private*/ 11 | public class RemoveFailedItemTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public var ioError : Event; 17 | public function RemoveFailedItemTest(name : String) : void { 18 | super(name); 19 | this.name = name; 20 | } 21 | // Override the run method and begin the request for remote data 22 | public override function setUp():void { 23 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 24 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/bad-some-text.jpg", {"priority":-200, id:"text"}); 25 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/badshoes.jpg", {"priority":-200, id:"photo"}); 26 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/bad-samplexm l.xml", {"priority":200, id:"xml"}); 27 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/bad.xml", {"priority":200, id:"xml2"}); 28 | 29 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 30 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 31 | _bulkLoader.addEventListener(BulkLoader.ERROR, onError); 32 | _bulkLoader.start(); 33 | } 34 | 35 | public function onError(evt : ErrorEvent) : void{ 36 | ioError = evt; 37 | // are we all set? 38 | completeHandler(evt); 39 | // call the on complete manually 40 | 41 | 42 | } 43 | 44 | public function completeHandler(event:Event):void { 45 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 46 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 47 | _bulkLoader.removeEventListener(BulkLoader.ERROR, onError); 48 | dispatchEvent(new Event(Event.INIT)); 49 | } 50 | 51 | 52 | /** This also works as an assertion that event progress will never be NaN 53 | */ 54 | public function progressHandler(event:ProgressEvent):void { 55 | //var evt : * = event as Object; 56 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 57 | var delta : Number = current - lastProgress; 58 | if (current > lastProgress && delta > 0.099){ 59 | lastProgress = current; 60 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 61 | } 62 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 63 | if (isNaN(event[propName]) ){ 64 | trace(propName, "is not a number" ); 65 | assertFalse(isNaN(event[propName])); 66 | } 67 | } 68 | } 69 | 70 | 71 | override public function tearDown():void { 72 | _bulkLoader.clear(); 73 | BulkLoader.removeAllLoaders(); 74 | _bulkLoader = null; 75 | } 76 | 77 | 78 | 79 | public function testRemoveAllKeepsOtherItems():void{ 80 | var itemsLeft : int = _bulkLoader.getFailedItems().length; 81 | var itemsToLoad : int = _bulkLoader.items.length - itemsLeft; 82 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/chopin.mp3") 83 | _bulkLoader.removeFailedItems(); 84 | assertEquals(_bulkLoader.items.length , 1 + itemsToLoad); 85 | } 86 | 87 | 88 | 89 | public function testContentAfterRemoveAll():void{ 90 | _bulkLoader.removeAll(); 91 | var numItems : int = 0; 92 | for (var prop:String in _bulkLoader._contents){ 93 | numItems ++; 94 | } 95 | // how many items in contents 96 | assertEquals(0, numItems); 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ResumeAllTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.*; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class ResumeAllTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | public var neverStopped : Boolean; 15 | 16 | public var ioError : Event; 17 | public var timer : Timer; 18 | public function ResumeAllTest(name : String) : void { 19 | super(name); 20 | this.name = name; 21 | } 22 | // Override the run method and begin the request for remote data 23 | public override function setUp():void { 24 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 25 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/large-file.txt"; 26 | 27 | _bulkLoader.add(goodURL, {id:"text", "preventCache":true}); 28 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/large-file.xml", {id:"xml", "preventCache":true}); 29 | _bulkLoader.get("text").addEventListener(BulkLoader.ERROR, onIOError); 30 | 31 | _bulkLoader.start(); 32 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 33 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 34 | } 35 | 36 | public function onIOError(evt : Event) : void{ 37 | ioError = evt; 38 | // call the on complete manually 39 | completeHandler(evt); 40 | tearDown(); 41 | } 42 | 43 | public function completeHandler(event:Event):void { 44 | //trace(_bulkLoader.getStats()); 45 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 46 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 47 | dispatchEvent(new Event(Event.INIT)); 48 | } 49 | 50 | public function doResume(evt : Event) : void{ 51 | _bulkLoader.resumeAll(); 52 | 53 | } 54 | /** This also works as an assertion that event progress will never be NaN 55 | */ 56 | public function progressHandler(event:ProgressEvent):void { 57 | if(!_bulkLoader.get("text").status != LoadingItem.STATUS_STOPPED && neverStopped){ 58 | _bulkLoader.pauseAll(); 59 | timer = new Timer(1000, 1); 60 | timer.addEventListener(TimerEvent.TIMER_COMPLETE, doResume); 61 | timer.start(); 62 | neverStopped = false; 63 | } 64 | //var evt : * = event as Object; 65 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 66 | var delta : Number = current - lastProgress; 67 | if (current > lastProgress && delta > 0.099){ 68 | lastProgress = current; 69 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 70 | } 71 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 72 | if (isNaN(event[propName]) ){ 73 | trace(propName, "is not a number" ); 74 | assertFalse(isNaN(event[propName])); 75 | } 76 | } 77 | } 78 | 79 | 80 | 81 | override public function tearDown():void { 82 | _bulkLoader.clear(); 83 | BulkLoader.removeAllLoaders(); 84 | _bulkLoader = null; 85 | } 86 | 87 | public function testResumeAll():void { 88 | var keysToCheck : Array = ["text", "xml"]; 89 | keysToCheck.forEach(function(key:String, ...rest):void{ 90 | var item : LoadingItem = _bulkLoader.get(key); 91 | assertNotNull(item); 92 | assertTrue(item.status == LoadingItem.STATUS_FINISHED); 93 | assertTrue(_bulkLoader.get(key).content.toString().length > 200); 94 | }); 95 | 96 | } 97 | 98 | } 99 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/ResumeTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.*; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; import br.com.stimuli.loading.BulkLoader; 8 | import br.com.stimuli.loading.loadingtypes.*; 9 | /**@private*/ 10 | public class ResumeTest extends TestCase { 11 | public var _bulkLoader : BulkLoader; 12 | public var lastProgress : Number = 0; 13 | public var neverStopped : Boolean; 14 | 15 | public var ioError : Event; 16 | public var timer : Timer; 17 | public function ResumeTest(name : String) : void { 18 | super(name); 19 | this.name = name; 20 | } 21 | // Override the run method and begin the request for remote data 22 | public override function setUp():void { 23 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 24 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/large-file.txt"; 25 | var badURL : String = "http://www.emptywhite.com/bulkloader-assets/bad-text.txt" 26 | var theURL : String = goodURL; 27 | if (this.name == 'testIOError'){ 28 | theURL = badURL; 29 | } 30 | 31 | _bulkLoader.add(theURL, {id:"text", "preventCache":true}); 32 | _bulkLoader.get("text").addEventListener(BulkLoader.ERROR, onIOError); 33 | 34 | _bulkLoader.start(); 35 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 36 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 37 | } 38 | 39 | public function onIOError(evt : Event) : void{ 40 | ioError = evt; 41 | // call the on complete manually 42 | completeHandler(evt); 43 | tearDown(); 44 | } 45 | 46 | public function completeHandler(event:Event):void { 47 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 48 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 49 | dispatchEvent(new Event(Event.INIT)); 50 | } 51 | 52 | public function doResume(evt : Event) : void{ 53 | _bulkLoader.resume("text"); 54 | 55 | } 56 | /** This also works as an assertion that event progress will never be NaN 57 | */ 58 | public function progressHandler(event:ProgressEvent):void { 59 | if(!_bulkLoader.get("text").status != LoadingItem.STATUS_STOPPED && neverStopped){ 60 | _bulkLoader.get("text").stop(); 61 | timer = new Timer(1000, 1); 62 | timer.addEventListener(TimerEvent.TIMER_COMPLETE, doResume); 63 | timer.start(); 64 | neverStopped = false; 65 | } 66 | //var evt : * = event as Object; 67 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 68 | var delta : Number = current - lastProgress; 69 | if (current > lastProgress && delta > 0.099){ 70 | lastProgress = current; 71 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 72 | } 73 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 74 | if (isNaN(event[propName]) ){ 75 | trace(propName, "is not a number" ); 76 | assertFalse(isNaN(event[propName])); 77 | } 78 | } 79 | } 80 | 81 | 82 | 83 | override public function tearDown():void { 84 | _bulkLoader.clear(); 85 | BulkLoader.removeAllLoaders(); 86 | _bulkLoader = null; 87 | } 88 | 89 | public function testResume():void { 90 | var item : LoadingItem = _bulkLoader.get("text"); 91 | assertNotNull(item); 92 | assertTrue(item.status == LoadingItem.STATUS_FINISHED); 93 | assertNotNull(_bulkLoader.getText("text")); 94 | } 95 | 96 | } 97 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/StartPausedTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import flash.net.URLRequest; 3 | import flash.net.*; 4 | import flash.events.*; 5 | import flash.utils.*; 6 | import flash.display.*; 7 | import br.com.stimuli.kisstest.TestCase; 8 | import br.com.stimuli.loading.BulkLoader; 9 | import br.com.stimuli.loading.loadingtypes.*; 10 | /**@private*/ 11 | public class StartPausedTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | public var ioError : Event; 17 | 18 | public var completeFired : Boolean; 19 | public var progressFired : Boolean; 20 | 21 | public function StartPausedTest(name : String) : void { 22 | super(name); 23 | this.name = name; 24 | } 25 | // Override the run method and begin the request for remote data 26 | public override function setUp():void { 27 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 28 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/some-text.txt"; 29 | 30 | _bulkLoader.add(goodURL, {id:"text"}); 31 | 32 | //_bulkLoader.start(); 33 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 34 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 35 | var timer : Timer = new Timer(2000, 1); 36 | timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerDone); 37 | timer.start(); 38 | } 39 | 40 | 41 | public function onTimerDone(evt : Event) : void{ 42 | evt.target.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerDone); 43 | evt.target.reset(); 44 | dispatchEvent(new Event(Event.INIT)); 45 | } 46 | public function onIOError(evt : Event) : void{ 47 | ioError = evt; 48 | // call the on complete manually 49 | completeHandler(evt); 50 | tearDown(); 51 | } 52 | 53 | public function completeHandler(event:Event):void { 54 | completeFired = true; 55 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 56 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 57 | 58 | } 59 | 60 | 61 | /** This also works as an assertion that event progress will never be NaN 62 | */ 63 | public function progressHandler(event:ProgressEvent):void { 64 | progressFired = true; 65 | //var evt : * = event as Object; 66 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 67 | var delta : Number = current - lastProgress; 68 | if (current > lastProgress && delta > 0.099){ 69 | lastProgress = current; 70 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 71 | } 72 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 73 | if (isNaN(event[propName]) ){ 74 | trace(propName, "is not a number" ); 75 | assertFalse(isNaN(event[propName])); 76 | } 77 | } 78 | } 79 | 80 | 81 | 82 | override public function tearDown():void { 83 | _bulkLoader.clear(); 84 | BulkLoader.removeAllLoaders(); 85 | _bulkLoader = null; 86 | } 87 | 88 | public function testContentExists():void { 89 | assertFalse(completeFired); 90 | assertFalse(progressFired); 91 | assertEquals(_bulkLoader.bytesLoaded, 0); 92 | } 93 | 94 | 95 | } 96 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/TwoItemsWithTheSameURLTest.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase; 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.display.*; 7 | import flash.events.*; 8 | import flash.net.*; 9 | import flash.utils.*; 10 | /**@private*/ 11 | public class TwoItemsWithTheSameURLTest extends TestCase { 12 | public var _bulkLoader : BulkLoader; 13 | public var lastProgress : Number = 0; 14 | 15 | 16 | 17 | 18 | 19 | public function TwoItemsWithTheSameURLTest(name : String) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | // Override the run method and begin the request for remote data 24 | public override function setUp():void { 25 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 26 | var goodURL : String = "http://www.emptywhite.com/bulkloader-assets/some-text.txt"; 27 | 28 | _bulkLoader.add(goodURL, {id:"1", preventCache: true}); 29 | _bulkLoader.add(goodURL, {id:"2", preventCache: true}); 30 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 31 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 32 | _bulkLoader.addEventListener(BulkLoader.ERROR, onError); 33 | _bulkLoader.start(); 34 | } 35 | 36 | public function onError(evt : Event) : void{ 37 | 38 | 39 | } 40 | 41 | public function onGoodURLLoaded(evt : Event): void{ 42 | completeHandler(evt); 43 | } 44 | public function completeHandler(event:Event):void { 45 | //super.run(); 46 | dispatchEvent(new Event(Event.INIT)); 47 | } 48 | 49 | 50 | /** This also works as an assertion that event progress will never be NaN 51 | */ 52 | public function progressHandler(event:ProgressEvent):void { 53 | } 54 | 55 | 56 | 57 | override public function tearDown():void { 58 | _bulkLoader.clear(); 59 | BulkLoader.removeAllLoaders(); 60 | _bulkLoader = null; 61 | } 62 | 63 | 64 | 65 | public function testItemsAreLoaded() : void{ 66 | assertNotNull(_bulkLoader.getText("1")); 67 | assertNotNull(_bulkLoader.getText("2")); 68 | } 69 | 70 | public function testItemsAreNotTheSame() : void{ 71 | var i1 : LoadingItem = _bulkLoader.get("1"); 72 | var i2 : LoadingItem = _bulkLoader.get("2"); 73 | assertFalse(_bulkLoader.get("1") == _bulkLoader.get("2")) ; 74 | } 75 | 76 | } 77 | } -------------------------------------------------------------------------------- /tests/src/br/com/stimuli/loading/tests/VideoContentPausedAtStartTestCase.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.loading.tests { 2 | import br.com.stimuli.kisstest.TestCase 3 | import br.com.stimuli.loading.BulkLoader; 4 | import br.com.stimuli.loading.loadingtypes.*; 5 | 6 | import flash.events.*; 7 | import flash.net.*; 8 | import flash.utils.getTimer; 9 | /**@private*/ 10 | public class VideoContentPausedAtStartTestCase extends TestCase{ 11 | public var _bulkLoader : BulkLoader; 12 | public var lastProgress : Number = 0; 13 | public var startEventFiredTime : Number; 14 | public var netStreamAtStart : NetStream; 15 | 16 | public var canBeginPlayingCount : int = 0; 17 | 18 | // Override the run method and begin the request for remote data 19 | public function VideoContentPausedAtStartTestCase(name: String) : void { 20 | super(name); 21 | this.name = name; 22 | } 23 | 24 | public override function setUp():void { 25 | _bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) 26 | _bulkLoader.add("http://www.emptywhite.com/bulkloader-assets/movie.flv", {id:"the-movie", pausedAtStart:true, preventCache:true}); 27 | _bulkLoader.get("the-movie").addEventListener(BulkLoader.OPEN, onVideoStartHandler); 28 | _bulkLoader.start(); 29 | _bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); 30 | _bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); 31 | _bulkLoader.get("the-movie").addEventListener(BulkLoader.CAN_BEGIN_PLAYING, onHasBeginPlayerFiredHandler); 32 | } 33 | 34 | public function completeHandler(event:Event):void { 35 | _bulkLoader.removeEventListener(BulkLoader.COMPLETE, completeHandler); 36 | _bulkLoader.removeEventListener(BulkLoader.PROGRESS, progressHandler); 37 | dispatchEvent(new Event(Event.INIT)); 38 | } 39 | 40 | 41 | /** This also works as an assertion that event progress will never be NaN 42 | */ 43 | public function progressHandler(event:ProgressEvent):void { 44 | //var evt : * = event as Object; 45 | var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; 46 | var delta : Number = current - lastProgress; 47 | if (current > lastProgress && delta > 0.099){ 48 | lastProgress = current; 49 | if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; 50 | } 51 | for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ 52 | if (isNaN(event[propName]) ){ 53 | trace(propName, "is not a number" ); 54 | assertFalse(isNaN(event[propName])); 55 | } 56 | } 57 | } 58 | 59 | public function onHasBeginPlayerFiredHandler(event : Event) : void{ 60 | canBeginPlayingCount ++; 61 | } 62 | 63 | protected function onVideoStartHandler(evt : Event) : void{ 64 | startEventFiredTime = getTimer(); 65 | netStreamAtStart = evt.target.content; 66 | } 67 | 68 | 69 | 70 | override public function tearDown():void { 71 | _bulkLoader.clear(); 72 | BulkLoader.removeAllLoaders(); 73 | _bulkLoader = null; 74 | } 75 | 76 | public function testVideoPausedAtStart():void { 77 | assertTrue(netStreamAtStart.time < 0.1); 78 | } 79 | 80 | public function testCanBeginPlayingEvent() : void{ 81 | assertEquals(canBeginPlayingCount, 1); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/TestResult.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest{ 2 | import flash.utils.getQualifiedClassName; 3 | 4 | import br.com.stimuli.kisstest.events.*; 5 | public class TestResult{ 6 | /** 7 | * In seconds! 8 | */ 9 | public var elapsedTime : Number; 10 | 11 | public var test : TestCase; 12 | public var error : Error; 13 | public var resultEvent : TestResultEvent ; 14 | 15 | 16 | 17 | public function TestResult(test : TestCase, elapsedTime : int){ 18 | this.test = test; 19 | } 20 | 21 | public function toString(verbose : Boolean = false) : String{ 22 | var simple :String = "[" + getQualifiedClassName(this) + "]" + test.toString(); 23 | if(verbose){ 24 | simple += ", status=" + test.status; 25 | } 26 | return simple; 27 | } 28 | 29 | public function get stackTrace() : String{ 30 | if (test.error){ 31 | return test.error.message + "\n" + test.error.getStackTrace(); 32 | }else if (test.fails.length > 0){ 33 | return test.fails[0].stack; 34 | } 35 | return ""; 36 | } 37 | 38 | public function get numAsserts() : int{ 39 | return test.assertsRan; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/TestSuite.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest{ 2 | 3 | import flash.utils.describeType; 4 | 5 | public class TestSuite{ 6 | 7 | public var numAsserts : int = 0; 8 | 9 | public var allTestsClasses : Array; 10 | public var allTests : Array; 11 | public var results : Array; 12 | public var runIndex : int = 0; 13 | 14 | public function TestSuite(...testClasses){ 15 | allTests = []; 16 | results = []; 17 | allTestsClasses = []; 18 | testClasses.forEach(function(o : Class, ...rest):void{ 19 | addTestCase(o); 20 | }) 21 | } 22 | 23 | public function addTestCase(testOrSuiteKlass : Class) : void{ 24 | var classes : Array = []; 25 | if (testOrSuiteKlass is TestSuite){ 26 | classes = testOrSuiteKlass.allTestClasses.slice(); 27 | }else{ 28 | classes.push (testOrSuiteKlass) 29 | } 30 | for each (var testKlass : Class in classes){ 31 | allTestsClasses.push(testKlass); 32 | var testsOnThisClass : Array = extractTests(testKlass); 33 | for each(var test : TestCase in testsOnThisClass){ 34 | addTest(test); 35 | } 36 | } 37 | 38 | } 39 | 40 | public function addTest(test : TestCase ) : void{ 41 | allTests.push(test); 42 | } 43 | 44 | public function extractTests(fromClass : Class) : Array{ 45 | var tests : Array = []; 46 | for each (var name : String in describeType(fromClass).factory.method.@name){ 47 | if (name.substr(0, 4) == "test"){ 48 | tests.push(new fromClass(name)); 49 | } 50 | } 51 | return tests; 52 | } 53 | 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/events/AssertionFailedEvent.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest.events{ 2 | import flash.events.Event; 3 | import br.com.stimuli.kisstest.TestCase; 4 | public class AssertionFailedEvent extends TestResultEvent{ 5 | 6 | public var expected : *; 7 | public var returned : *; 8 | public var stack : String; 9 | public static const ASSERT_FAILED : String = "assertFailed"; 10 | public function AssertionFailedEvent( expected : *, returned : * = null, stack : String= ""){ 11 | super(new TestCase(""), null, ASSERT_FAILED); 12 | this.expected = expected; 13 | this.returned = returned; 14 | this.stack = stack; 15 | 16 | } 17 | 18 | override public function toString() : String{ 19 | return "Expected "+( expected != null ? expected.toString() : "") + ", got: " + (returned != null ? returned.toString() : ""); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/events/AssertionSuccessEvent.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest.events 2 | { 3 | import flash.events.Event; 4 | 5 | import br.com.stimuli.kisstest.TestCase; 6 | 7 | 8 | public class AssertionSuccessEvent extends TestResultEvent 9 | { 10 | public static const ASSERT_SUCCESS : String = "assertSuccess"; 11 | 12 | public function AssertionSuccessEvent(test:TestCase=null) 13 | { 14 | super(null, null, ASSERT_SUCCESS); 15 | } 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/events/TestEvent.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest.events{ 2 | import flash.events.Event; 3 | 4 | import br.com.stimuli.kisstest.TestCase; 5 | 6 | 7 | public class TestEvent extends Event{ 8 | public static const TEST_FINISHED : String = "testFinished"; 9 | public static const TEST_SUCCEEDED : String = "testSucceeded"; 10 | public static const TEST_STARTED : String = "testStarted"; 11 | public static const TEST_FAILED : String = "testFinished"; 12 | public static const TEST_ERROR : String = "testError"; 13 | 14 | public var test : TestCase; 15 | public function TestEvent (name : String, test : TestCase){ 16 | super(name); 17 | this.test = test; 18 | if (!test){ 19 | throw new Error("Cannot create TestEvent will null test"); 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/events/TestResultEvent.as: -------------------------------------------------------------------------------- 1 | package br.com.stimuli.kisstest.events{ 2 | import flash.events.Event; 3 | import br.com.stimuli.kisstest.TestCase; 4 | import br.com.stimuli.kisstest.TestResult; 5 | public class TestResultEvent extends Event{ 6 | 7 | public var test : TestCase; 8 | public var testResult : TestResult; 9 | 10 | public function TestResultEvent( test : TestCase, testResult : TestResult, name : String = Event.COMPLETE){ 11 | this.test = test; 12 | this.testResult = testResult; 13 | super(name); 14 | } 15 | 16 | override public function toString() : String{ 17 | return "[TestResultEvent] for test " + test ; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /tests/third-parties/src/br/com/stimuli/kisstest/runners/TraceRunner.as: -------------------------------------------------------------------------------- 1 | package kisstest.runners 2 | { 3 | import br.com.stimuli.kisstest.TestRunner; 4 | import br.com.stimuli.kisstest.TestSuite; 5 | import br.com.stimuli.kisstest.events.TestEvent; 6 | import br.com.stimuli.kisstest.events.TestResultEvent; 7 | 8 | public class TraceRunner extends TestRunner 9 | { 10 | public function TraceRunner(testSuite : TestSuite) 11 | { 12 | super(testSuite); 13 | addEventListener(TestEvent.TEST_FINISHED, onTestDone); 14 | } 15 | 16 | public function onTestDone(evt:TestEvent):void{ 17 | 18 | //trace("Finished test:: -> " + evt.test, this.finishedTestCount + "/" + this.testCount); 19 | 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /tests/third-parties/src/com/adobe/serialization/json/JSON.as: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, Adobe Systems Incorporated 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Adobe Systems Incorporated nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | package com.adobe.serialization.json 34 | { 35 | 36 | /** 37 | * This class provides encoding and decoding of the JSON format. 38 | * 39 | * Example usage: 40 | * 41 | * // create a JSON string from an internal object 42 | * JSON.encode( myObject ); 43 | * 44 | * // read a JSON string into an internal object 45 | * var myObject:Object = JSON.decode( jsonString ); 46 | * 47 | */ 48 | public class JSON 49 | { 50 | /** 51 | * Encodes a object into a JSON string. 52 | * 53 | * @param o The object to create a JSON string for 54 | * @return the JSON string representing o 55 | * @langversion ActionScript 3.0 56 | * @playerversion Flash 9.0 57 | * @tiptext 58 | */ 59 | public static function encode( o:Object ):String 60 | { 61 | return new JSONEncoder( o ).getString(); 62 | } 63 | 64 | /** 65 | * Decodes a JSON string into a native object. 66 | * 67 | * @param s The JSON string representing the object 68 | * @param strict Flag indicating if the decoder should strictly adhere 69 | * to the JSON standard or not. The default of true 70 | * throws errors if the format does not match the JSON syntax exactly. 71 | * Pass false to allow for non-properly-formatted JSON 72 | * strings to be decoded with more leniancy. 73 | * @return A native object as specified by s 74 | * @throw JSONParseError 75 | * @langversion ActionScript 3.0 76 | * @playerversion Flash 9.0 77 | * @tiptext 78 | */ 79 | public static function decode( s:String, strict:Boolean = true ):* 80 | { 81 | return new JSONDecoder( s, strict ).getValue(); 82 | } 83 | 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /tests/third-parties/src/com/adobe/serialization/json/JSONParseError.as: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, Adobe Systems Incorporated 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Adobe Systems Incorporated nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | package com.adobe.serialization.json { 34 | 35 | /** 36 | * 37 | * 38 | */ 39 | public class JSONParseError extends Error { 40 | 41 | /** The location in the string where the error occurred */ 42 | private var _location:int; 43 | 44 | /** The string in which the parse error occurred */ 45 | private var _text:String; 46 | 47 | /** 48 | * Constructs a new JSONParseError. 49 | * 50 | * @param message The error message that occured during parsing 51 | * @langversion ActionScript 3.0 52 | * @playerversion Flash 9.0 53 | * @tiptext 54 | */ 55 | public function JSONParseError( message:String = "", location:int = 0, text:String = "") { 56 | super( message ); 57 | name = "JSONParseError"; 58 | _location = location; 59 | _text = text; 60 | } 61 | 62 | /** 63 | * Provides read-only access to the location variable. 64 | * 65 | * @return The location in the string where the error occurred 66 | * @langversion ActionScript 3.0 67 | * @playerversion Flash 9.0 68 | * @tiptext 69 | */ 70 | public function get location():int { 71 | return _location; 72 | } 73 | 74 | /** 75 | * Provides read-only access to the text variable. 76 | * 77 | * @return The string in which the error occurred 78 | * @langversion ActionScript 3.0 79 | * @playerversion Flash 9.0 80 | * @tiptext 81 | */ 82 | public function get text():String { 83 | return _text; 84 | } 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /tests/third-parties/src/com/adobe/serialization/json/JSONToken.as: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, Adobe Systems Incorporated 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Adobe Systems Incorporated nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | package com.adobe.serialization.json { 34 | 35 | public class JSONToken { 36 | 37 | private var _type:int; 38 | private var _value:Object; 39 | 40 | /** 41 | * Creates a new JSONToken with a specific token type and value. 42 | * 43 | * @param type The JSONTokenType of the token 44 | * @param value The value of the token 45 | * @langversion ActionScript 3.0 46 | * @playerversion Flash 9.0 47 | * @tiptext 48 | */ 49 | public function JSONToken( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null ) { 50 | _type = type; 51 | _value = value; 52 | } 53 | 54 | /** 55 | * Returns the type of the token. 56 | * 57 | * @see com.adobe.serialization.json.JSONTokenType 58 | * @langversion ActionScript 3.0 59 | * @playerversion Flash 9.0 60 | * @tiptext 61 | */ 62 | public function get type():int { 63 | return _type; 64 | } 65 | 66 | /** 67 | * Sets the type of the token. 68 | * 69 | * @see com.adobe.serialization.json.JSONTokenType 70 | * @langversion ActionScript 3.0 71 | * @playerversion Flash 9.0 72 | * @tiptext 73 | */ 74 | public function set type( value:int ):void { 75 | _type = value; 76 | } 77 | 78 | /** 79 | * Gets the value of the token 80 | * 81 | * @see com.adobe.serialization.json.JSONTokenType 82 | * @langversion ActionScript 3.0 83 | * @playerversion Flash 9.0 84 | * @tiptext 85 | */ 86 | public function get value():Object { 87 | return _value; 88 | } 89 | 90 | /** 91 | * Sets the value of the token 92 | * 93 | * @see com.adobe.serialization.json.JSONTokenType 94 | * @langversion ActionScript 3.0 95 | * @playerversion Flash 9.0 96 | * @tiptext 97 | */ 98 | public function set value ( v:Object ):void { 99 | _value = v; 100 | } 101 | 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /tests/third-parties/src/com/adobe/serialization/json/JSONTokenType.as: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, Adobe Systems Incorporated 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Adobe Systems Incorporated nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | package com.adobe.serialization.json { 34 | 35 | /** 36 | * Class containing constant values for the different types 37 | * of tokens in a JSON encoded string. 38 | */ 39 | public class JSONTokenType { 40 | 41 | public static const UNKNOWN:int = -1; 42 | 43 | public static const COMMA:int = 0; 44 | 45 | public static const LEFT_BRACE:int = 1; 46 | 47 | public static const RIGHT_BRACE:int = 2; 48 | 49 | public static const LEFT_BRACKET:int = 3; 50 | 51 | public static const RIGHT_BRACKET:int = 4; 52 | 53 | public static const COLON:int = 6; 54 | 55 | public static const TRUE:int = 7; 56 | 57 | public static const FALSE:int = 8; 58 | 59 | public static const NULL:int = 9; 60 | 61 | public static const STRING:int = 10; 62 | 63 | public static const NUMBER:int = 11; 64 | 65 | public static const NAN:int = 12; 66 | 67 | } 68 | 69 | } --------------------------------------------------------------------------------