Mar 18 2007

Instantiating ActionScript 3.0 classes at runtime, and a Flex compiler trick

Tag: FlexDerek Wischusen @ 3:49 am

I’ve been playing around with dynamically instantiating classes in AS 3.0 a lot lately and I thought I would share a couple of tricks that I’ve come across.

You can instantiate a class at runtime using the getDefinitionByName(name:String):Object method in the flash.utils package. To use this method, you simply have to pass it the name of the class that you want to create.

Here are couple good posts that explain how to use this method:

Both of these posts point out that one of the limitations of this method is that the class that you want to create needs to be compiled into your application and that Flex only compiles in classes that are explicitly referenced in your application. This is obviously a major drawback, since one the main reasons that you would want to use dynamic instantion is to create classes that are not already referenced in you app.

So, I did a little searching and I found that there is a way to instantiate a class at runtime that is not explicitly referenced in your application.

Here’s how:

1. Put the classes that you want to instantiate at runtime in a Flex Library Project.

2. In the project for your application, add the .swc that is generated by the library project to the library path.

3. In the compiler arguments for your application add -include-libraries <path_to_swc>

The -include-libraries compiler argument tells the compiler that you want to load all of the classes in the library, even the ones that are not referenced anywhere.

Once you’ve done this, you will be able to load any of the classes in the library at runtime.

Now for the compiler trick:

If you go into the application that loads the library and create classes that have same name and namespace as the classes in your library project, the compiler will load the classes that are in your main application. This means that the library project only needs to contain empty classes that mirror the classes in your application that you want to instantiate at runtime.

For example, let’s say that you have a class called GetUser that you want to instantiate at runtime. If you follow the instructions from above you will have a Flex Library Project and Flex application that loads the SWC that is generated by the library.

Now, let’s say that you’ve put the AddUser class in the following package in your library project

com.mycomp.myproj.command.AddUser

If you put an AddUser class in the com.mycomp.myproj.command package in your Flex application project, when you instantiate the class at runtime the Flex will create the class that is in your Flex application project.

WARNING: The tricks that I described seem to make Flex very unhappy. If you want to test them out I suggest that you use new projects in a new workspace.

Please let me know if you have any questions about any of this.


Mar 05 2007

JRuby + RED 5 = Ruby + RTMP

Tag: JRuby, RTMP, Red 5Derek Wischusen @ 12:51 am

JRuby is, in my opinion, one of the most exciting projects out there. Primarily because it makes it possible for Ruby developers to take advantage of all the technologies that have been built in Java. In particular, it makes it possible to take advantage of one of the other most exciting projects out there: Red 5.

Red5 is an Open Source Flash Server written in Java that supports:

  • Streaming Audio/Video (FLV and MP3)
  • Recording Client Streams (FLV only)
  • Shared Objects
  • Live Stream Publishing
  • Remoting

Red 5 is, or very soon will be, a viable free, open source alternative to Flash Media Server. Most important of all to the Ruby community is the fact that Red 5 recently added a scripting framework that makes it possible to use it with Ruby (via JRuby), as well as Javascript (via Rhino), Python (via Jython), and Groovy. Though, even if there was no scripting framework in Red 5, it should now be relatively easy to do using a simple wrapper class in Java that loads your Ruby classes using the new scripting framework in Java 6.

To get started with Red 5 and Ruby, first download a copy of Red 5, then check out this tutorial by Paul Gregoire.

If you want to try to use Rails with from the scripting framework in Red 5, then be sure to read the ‘Gotchas’ at the bottom of this page.

More to come on this in future posts.


Propecia price
Viagra discount coupons
Order xanax cod
Where can i buy viagra without a prescription
Discount viagra online
Generic viagra 100mg
Cialis prescription cost
Best viagra dose
Viagra buy online no prescription
Valium online uk
Fedex tramadol
Xanax no prescription required
Genuine viagra online
Buy cialis online from canada
Buy propecia
Buy viagra australia
Valium online overnight
Levitra online buy
Order prednisone no prescription
Cheap tramadol overnight delivery
Cheapest cialis professional
Drug phentermine
Buy xanax online without prescription
Prescriptions for phentermine
Ordering cialis online
Purchase phentermine online
Discount viagra pills
Tramadol medication
Valium from india
Buy valium no rx
Where to buy viagra online
Cialis for sale
Prednisone online
Cheap cialis
Cialis samples canada
Viagra online without prescription reviews
Phentermine purchase online
Viagra canada prices
Buy viagra online in australia
Cialis soft tabs online
Phentermine diet pills without prescription
Prescription valium
Buy xanax cheap online
Buying viagra in london
Where to buy propecia in canada
Buy phentermine hcl 37.5 no prescription
Cheapest generic viagra online
Buy viagra in canada online
Viagra tablets for sale
Viagra in the uk
Where can i buy viagra without prescription
Valium drug side effects
Buy cialis in the uk
Viagra ordering
Pharmacy tramadol
Brand viagra cheap
Purchase phentermine without prescription
Buy phentermine 37.5mg online
Buy tramadol cod
Buy levitra
Order cheap phentermine
Generic viagra sales
How to buy phentermine online
Generic tramadol
Propecia cheap
Propecia best prices
Prescription viagra uk
Phentermine 37.5mg side effects
Cheapest online cialis
Buy xanax overnight
Order tramadol online cod
Online prescriptions xanax
Tramadol prescription online
Prescription free viagra
Cialis medication
Xanax bars effects
Where can i buy viagra in the uk
Tramadol online overnight
Valium without prescription uk
Pfizer viagra price
Canada viagra
Viagra generic
Xanax no rx
Valium generic
Viagra purchase uk
Viagra super active
Propecia ireland
Viagra price canada
Viagra online uk
Cheapest place to buy viagra online
Levitra 20mg
Where to buy cialis online
Best viagra alternative
Buy cheap valium online
Authentic phentermine 37.5
Best way to buy viagra online
Buy viagra 100mg
Online prescription tramadol
Cheapest levitra
Ordering propecia from canada
Buy valium without prescription uk
Viagra pharmacy prices
Viagra pharmacy uk
Tramadol without prescription overnight delivery
Viagra no prescription online
Buy phentermine no script
Generic cialis overnight
Cheap generic viagra
Free cialis online
Phentermine 37.5mg
Best way to take tramadol
Discount viagra usa
Australia viagra prescription
Low cost cialis
Get tramadol prescription
Purchase levitra online
Generic xanax
Side effects of viagra
Xanax generic dosage
Buy levitra online canada
Buy cialis uk
Cost of viagra 50mg
Viagra in france
Cialis side effects
Cheap xanax bars
Best price tramadol
Brand name cialis
Buying tramadol in uk
Overnight delivery viagra
Phentermine buy uk
Buy tramadol hcl
Viagra for sale online
Buy viagra online cheap
Xanax online cheap
Xanax bars dosage
Cialis 20 mg dosage
Buy phentermine online no prescription
Mail order phentermine
Order phentermine online no prescription
Cheap propecia without prescription
Prescription propecia
Viagra in usa
Get viagra
Propecia 1mg generic
Cheap viagra online without prescription
Propecia cost
Phentermine 37.5 mg
Buy cheap viagra online uk
Purchase cialis without a prescription
Buy generic xanax no prescription
Free cialis samples
Propecia generic online
Generic xanax xr
How to buy valium without a prescription
Viagra professional online
Levitra price
Xanax price per pill
Low cost levitra
Prednisone 20mg side effects
Overnight tramadol no prescription
Tramadol for sale
Buying valium in spain
Free samples of cialis
Buy tramadol overnight
Where to buy levitra online
Canada pharmacy valium
Order cheap viagra online
Generic viagra for sale
Phentermine cheap online
Order tramadol overnight
Generic xanax no prescription
Buy phentermine 37.5mg pills
Buying xanax online without prescription
Prednisone tablets 10 mg
Buy viagra from canada
Valium pill 10mg
Viagra online purchase in india
Real phentermine without prescription
Where to buy cialis without prescription
Cheap generic valium
Buy pfizer viagra without prescription
Cheap 100mg viagra
Xanax 1 mg dose
Propecia uk pharmacy
Low price viagra
Viagra generic cheap
Buy generic phentermine online
Buy valium europe
Levitra samples
10mg prednisone
Cheap phentermine without prescription
Cialis purchase online
Where to buy viagra in england
Cialis 10mg side effects
Cialis 20mg side effects
Phentermine hcl without prescription
Viagra express delivery
Generic levitra uk
Tramadol dosage
No prescription valium
Viagra sale uk
Viagra 50 mg online without prescription
Viagra prescription cost
Phentermine canadian pharmacy
Cialis over the counter
Best price cialis
Buy propecia online without a prescription
Xanax with no prescription
Where to buy phentermine cheap
Levitra canada
Prednisone 40 mg
Cialis price
Tramadol india
Xanax no prescription overnight
Purchase phentermine
Viagra india price
Cheap cialis pills
40 mg prednisone side effects
Xanax 1mg
Cialis uk sales

Prescription phentermine online
Tramadol cheapest
Valium 10 mg
Buy cialis viagra
Cheap valium online
Propecia generic canada
Buy viagra uk online
Buy viagra online in ireland
Buy viagra online uk no prescription
Phentermine online uk
Buying viagra in new zealand
Cheap cialis viagra
Buy viagra in england
Buy generic propecia uk
Levitra online cheap
Cheap xanax for sale
Buy xanax canada
Valium no rx
Tramadol no prescription required
Levitra online
Cialis dosage 20mg
Viagra canadian online pharmacy
Purchase viagra online without prescription
Buy valium cheap online
Prescription viagra canada
Prednisone tablets
Propecia uk prices
Viagra without prescription uk
Phentermine online free shipping