---
id: 48
title: 'Adobe Flex : Dynamically loading classes at runtime'
slug: adobe-flex-dynamically-loading-classes-at-runtime
date: '2007-11-15T23:38:00Z'
modified: '2007-11-15T23:38:00Z'
status: publish
type: post
author: pmoelgaard
categories:
  - ActionScript 3.0
  - Adobe Flex
tags: []
excerpt: null
canonicalPath: /posts/adobe-flex-dynamically-loading-classes-at-runtime
featuredImage: null
commentCount: 0
wordCount: 113
readingTimeMinutes: 1
hasMedia: false
hasVideos: false
url: >-
  https://forwardthinking.pemo.me/posts/adobe-flex-dynamically-loading-classes-at-runtime
---
Loading classes dynamically is a powerful and very useful technique.  
Using the [SWFLoader](http://flex.org/mx.controls.SWFLoader) in the [controls](http://flex.org/mx.controls) package makes doing this straightforward ...  
  
var libraryLoader:SWFLoader = new SWFLoader();  
libraryLoader.source = "Library.swf";  
  
if( libraryLoader.loaderContext.applicationDomain.hasDefinition( "Foo" ) )  
{  
var FooClass:Class = libraryLoader.loaderContext.applicationDomain.getDefinition( "Foo" ) as Class;  
var fooInstance:\* = new FooClass();  
}  
  
An interesting aspect with this technique is the theoretical ability to have several classes with an equal fully qualified name in the same application instance as long as they are loaded from different applicationdomains. I cant foresee what eventually will happen in the case of a casting collision, but I intend to find out as soon as I have 15 minutes to spend.
