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

/**
* @author ahatch
*/
public class RuntimeLibraryItem extends EventDispatcher
{
public static const LOAD_COMPLETE:String = 'runtimeItemLoadComplete';
public static const LOAD_ERROR:String = 'runtimeItemSecurityError';

private var _loader:Loader;
private var _url:String;

public function RuntimeLibraryItem(url:String, autoLoad:Boolean = false)
{
_url = url;
init(autoLoad);
}

private function init(loadNow:Boolean = false):void
{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadComplete);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
_loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityError);

if(loadNow)
load();
}

public function load():void
{
_loader.load(new URLRequest(_url), new LoaderContext(false, ApplicationDomain.currentDomain));
}

public function getClass(className:String):Class
{
try
{
return _loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class;
}
catch (e:Error)
{
throw new IllegalOperationError(className + " definition not found in " + this);
}
return null;
}

protected function handleLoadComplete(event:Event):void
{
dispatchEvent(new Event(LOAD_COMPLETE, true));
}

private function handleIOError(event:IOErrorEvent):void
{
dispatchEvent(new Event(LOAD_ERROR, true));
}

private function handleSecurityError(e:Event):void
{
dispatchEvent(new Event(LOAD_ERROR, true));
}

public function get loader():Loader
{
return _loader;
}

public function get url():String
{
return _url;
}

public function set url(value:String):void
{
_url = value;
}
}
}

Change log

r84 by andyghatch on Dec 14, 2009   Diff
dispatch error on IO Error
Go to: 
Project members, sign in to write a code review

Older revisions

r78 by andyghatch on Jul 28, 2009   Diff
ignore properties, lib class name
change, lib class cleanup
All revisions of this file

File info

Size: 2135 bytes, 89 lines
Powered by Google Project Hosting