Jun 19 2007

Lightweight server push with Rails and AIR

Tag: AIR, Apollo, Flex, RailsDerek Wischusen @ 2:30 am

Alex MacCaw has posted a really nice example of how his Juggernaut plugin for server-side push can be used with Adobe’s AIR (formerly Apollo) runtime to create a simple chat application.


Jun 19 2007

Mixins in ActionScript 3

Tag: AS3Derek Wischusen @ 2:05 am

In a previous post I discussed how you can use the include statement to ‘mixin’ methods and properties defined in an ActionScript file into your classes. I find this approach to be somewhat limited, so I’ve put together a class that allows you to mix one class into another. The class is an all-static class that is simply called Mixin. The class is a bit long to include in this post, but you can view the source by clicking here.
Here is a quick example of how you can use this class. Let’s start with two classes that we will use as mixins:

public dynamic class ClassMixin
{
	import flash.utils.*;
 
	// bound method that retains reference to this class
	// this will always return the fully qualified path
	// to this class
	public function whoAmI () : String
	{
		return getQualifiedClassName(this);
	}
 
	// function expression that is attached to the prototype
	// this return the class name of the class that it is
	// called from
	prototype.whoBeMe = function () : String {
		return getQualifiedClassName(this);
	};
 
	// this will return the class object for the instance
	// that invokes it
	prototype.myClass = function () : Class {
		return getDefinitionByName(this.whoBeMe()) as Class;
	};
}
public class Ext
{
	public static var staticVar : Number = 123;
 
	public var instanceVar : Number = 321;
 
	public static function staticMethod () : String
	{
		return 'I am static';
	}
 
	public function instanceMethod () : String
	{
		return 'I am an instance';
	}
 
	public function iCallProtected () : String
	{
		return iAmProtected();
	}
 
	protected function iAmProtected () : String
	{
		return 'Protected';
	}
}

And a third class that is the mixee (the one that we will mix the other two classes into).

public dynamic class Model
{
	// dynamic reference to 'this' class object.
	private static var self : Class = prototype.constructor;
 
	// mixin classes during static init
	Mixin.extendClass(self, ClassMixin);
	Mixin.extendClass(self, Ext);		
 
	public function Model()
	{
 
	}
 
}

In the Model class above you will see two calls to Mixin.extendClass(). The extendClass method takes the class in the second argument and mixes its methods and properties (both static and instance) in to the class in the first argument. These extendClass method calls are made directly inside the class block, so they are invoked when the Model class object is initialized. You can read more about this in my previous post about static initializations in ActionScript.

So, now if you were to execute the following class:

public class Main extends Sprite
{
	public function Main()
	{
		var m : Model = new Model();
 
		//bound method returns original class name
		trace (m.whoAmI());
 
		// this function is not bound and it returns name
		// of the class that is calling the function
		trace (m.whoBeMe());
		trace(m.myClass());
 
		//mixed in from Ext
		trace (Model['staticMethod']());
		trace (m.instanceMethod());
		trace(m.myClass().staticVar);
		trace(m.instanceVar);
 
		// mixed in method calls a protected method in the Ext class
		trace (m.iCallProtected());
 
		// you can override methods that are attached to prototype at runtime
		Model.prototype.whoBeMe = function () : String {
			return 'I am you';
		};
		trace (m.whoBeMe());
 
	}	
 
}

You would see the following in the console:
com.rxr.mixinexample::ClassMixin
com.rxr.mixinexample::Model
[class Model]
I am static
I am an instance
123
321
Protected
I am you

You can view the full source and download it here.


Jun 15 2007

Static initializations in ActionScript, Take 2

Tag: ActionScriptDerek Wischusen @ 12:05 am

In a previous post I discussed how you can use the [Mixin] metadata tag to create a static initialization in Flex. Here is another way to do pretty much the same thing:

public dynamic class Model 
{ 
 
    trace('I get called first'); 
 
    public function Model() 
    { 
 
    } 
 
}

The trace statement and any other code that is directly inside the class body will be invoked when the class is loaded. You can read more about this here.


Jun 14 2007

Flex and RESTful Rails tutorial en francais

Tag: Flex and Rails, tutorialDerek Wischusen @ 9:03 pm

If you are interested and in Flex and Rails, and you know french, then be sure to check out this tutorial by Laurent Bois.


Jun 13 2007

Thinking about using Trac for project management? Then check out redMine

Tag: RailsDerek Wischusen @ 2:56 am

redMine is a very nice, open-source (GPL), project management application that is being built with Ruby on Rails. If you are thinking about using Trac for project managment, then I definitely recommend that you take a look at redMine. I found that redMine was quite a bit easier to install than Trac, and I also found that it was easier to manage multiple projects with redMine. Also, I just generally like redMine’s interface.

You can check out a demo of redMine here.


Jun 13 2007

Tony Hillerson of effectiveUI talks about Flex and Rails

Tag: Flex and RailsDerek Wischusen @ 2:36 am

In a two part interview on the Flex Show, Tony Hillerson of effectiveUI discusses the benefits of working with Rails and why you might want to use Rails as the back-end for your Flex apps.

Part 1

Part 2


Jun 13 2007

Ruby-like Mixins in ActionScript 3

Tag: AS3, RubyDerek Wischusen @ 2:26 am

That title may be a bit of a stretch, AS3 does not support mixins in the same way as Ruby, but it is possible to define a set of methods and/or attributes in a single file and then mix those methods and attributes into your AS3 classes. Here’s how:

First create a new ActionScript file (a file, not a class) then add the methods and/or attributes that you want to mix in to your classes.

For example, I created a file called classmixin.as that looks like this:

// ActionScript file 
 
	import flash.utils.*; 
 
        // returns the name of the class 
	public function whoAmI () : String 
	{ 
		return getQualifiedClassName(this); 
	} 
 
        // returns the class object 
	public function myClass () : Class 
	{ 
		return getDefinitionByName(whoAmI()) as Class; 
	} 
 
        // returns the prototype object 
	public function proto () : Object 
	{ 
		return myClass().prototype; 
	}

Now, let’s say that you want to add these methods directly to two classes, one is controller called ContactsController and one is a model called Contact. To do this you need to use the include statement along with the relative path to file that defines the methods. For example:

package com.rxr.mixinexample.control 
{ 
	public class ContactsController 
	{ 
		include "/../classmixin/classmixin.as" 
	} 
}
package com.rxr.mixinexample.model 
{ 
	public class Contact 
	{ 
		include "/../classmixin/classmixin.as" 
	} 
}

That’s it. Now both of these classes have all of the methods defined in classmixin.as, so if you were to run the following code:

package { 
	import flash.display.Sprite; 
	import com.rxr.mixinexample.control.ContactsController; 
	import com.rxr.mixinexample.model.Contact; 
 
	public class MixinExample extends Sprite 
	{ 
		public function MixinExample() 
		{ 
			var a : ContactsController = new ContactsController(); 
			var b : Contact = new Contact(); 
 
			trace(a.whoAmI()); 
			trace(b.whoAmI()); 
 
		} 
	} 
}

you would see these trace statements in the console:

com.rxr.mixinexample.control::ContactsController
com.rxr.mixinexample.model::Contact

This mixin capability in AS3 works a bit differently than mixins in Ruby. In Ruby when you mixin a module you are really creating a reference to that module and when you call a method that was mixed in it is actually being delegated to the module. Also, in Ruby when you mixin in a module only the member methods get mixed in, though there is way to mixin statics as well, but you have to add some extra code to make this happen. This is because the module is an object itself and the static methods belong to the module, so if you want to add them to your class you need to extend the module.

In AS3 when you include a .as file, it is though you are appending that file directly to the class definition. So you are not creating a reference to a module, you are just adding the contents of the file to your class, so if you define static attributes or methods they will be added to your class along with the member attributes and methods.

Please let me know if you have any questions, or if any of this is unclear.

You can grab the source files for this example here.


Propecia information
Where can i buy viagra in the uk
Blood pressure and prednisone
Levitra price
Viagra canadian online pharmacy
Buy propecia cheap
Viagra tablets for sale
Valium online fast delivery
Propecia ireland
Prescription viagra canada
Overnight tramadol no prescription
Tramadol without prescription overnight delivery
Tramadol online overnight
40 mg prednisone side effects
Purchase phentermine
Prednisone online
Generic viagra online without prescription
Buy generic propecia uk
Propecia generic online
10mg valium effects
Genuine viagra online
Buy propecia online without a prescription
Overnight xanax delivery
Phentermine diet pills without prescription
Cialis 20 mg dosage
Phentermine 37.5mg
Buy generic xanax no prescription
Buy phentermine no script
Best way to take tramadol
Cheap cialis india
Prescriptions for phentermine
Ordering propecia from canada
Prednisone tablets
Xanax buy uk
Cheap cialis pills
Cheap tramadol cod
Free cialis samples
Tramadol cod delivery
Tramadol for sale
Order prednisone no prescription
Buy brand name viagra
Canada viagra
100mg tramadol effects
Where can i buy cialis without a prescription
Where can i buy viagra without prescription
Cialis ordering
Cheap generic viagra
Valium online pharmacy
Xanax 1 mg dose
Tramadol cheapest
No prescription valium
Viagra shop online
Valium from india
Valium pill 10mg
Viagra online uk
Phentermine with no prescription
Propecia cost
Buy cialis in the uk
Valium no rx
Viagra super active
Prescription valium
Low price viagra
Propecia uk prices
Xanax with no prescription
Xanax no prescription overnight
Viagra fast delivery
Cialis canada no prescription
Viagra pharmacy prices
Valium online overnight
Phentermine buy australia
Viagra price canada
Valium online uk
Buy generic cialis
Buy female viagra without prescription
Phentermine online uk
Valium generic
Levitra purchase
Buying viagra online
Buy viagra from canada
Buy valium no rx
Buy cialis viagra
Buy xanax 2mg no prescription
Buying cialis
Cheap levitra uk
Buy viagra uk no prescription
Cialis dosage 20mg
Cheap generic valium
Online prescription tramadol
Cialis 20mg side effects
Discount viagra online
Cheap xanax bars
Phentermine 37.5 buy online
Xanax bars dosage
Cheap valium online
Viagra buy online no prescription
Phentermine 37.5 wholesale
Generic tramadol
Cialis over the counter
Tramadol pharmacy
Generic xanax no prescription
Generic cialis overnight
Best way to buy viagra online
Generic viagra sales
Where can i buy viagra without a prescription
Buy cheap valium online
Where to buy viagra online
Prescription viagra uk
Purchase levitra online
Cheap 100mg viagra
Order tramadol cod
Buy phentermine hcl 37.5 no prescription
Ordering cialis online
Dosage of xanax
Cheapest online cialis
Cialis order canada
Viagra professional online
Viagra cheap no prescription
Generic levitra uk
Viagra online cheap
Cialis cialis
Cialis prescription cost
Buy levitra online canada
Phentermine online free shipping
Purchase tramadol online
Viagra sale uk
Xanax online cheap
Buy tramadol hcl
Buying prednisone online
Buy viagra in canada online
Low cost cialis
Authentic phentermine 37.5
Levitra online buy
Where to buy cialis safely
Phentermine canada no prescription
Tramadol dosage
Buying levitra without prescription
Cialis for sale
Get viagra prescription
Cialis side effects
Buy viagra uk online
Order cheap viagra online
Buy generic cialis uk
Viagra 50mg side effects
Prescription propecia
Propecia price
Viagra dosage information
Order tramadol overnight
Viagra canada mastercard
Buying cialis online without a prescription
Cheapest cialis price
Online prescriptions xanax
Cheap propecia without prescription
Best price tramadol
Buy tramadol hydrochloride
Buy xanax cheap online
Viagra indian pharmacy
Viagra express delivery
Tramadol no prescription required
Buying viagra in london
Best prices for cialis
Buy phentermine no rx
Discount viagra pills
Generic viagra for sale
Cialis 20mg
No prescription cialis online
Valium drug side effects
Best price cialis
Phentermine 37.5 pills
Phentermine 37.5mg side effects
Levitra 20mg
Valium cheapest
Cheap phentermine without prescription
Valium 10 mg
Generic xanax xr
Prescription phentermine online
Side effects of viagra
Phentermine cheap online
Mail order phentermine
Viagra discount prices
Viagra in usa
Buy generic valium
Cialis 10mg side effects
Buy valium europe
Cialis order online
Levitra canada
Viagra generic cheap
Propecia price australia
Phentermine 37.5 mg
Prednisone 40 mg
Phentermine without a prescription
Free samples of cialis
Canada viagra no prescription
Order xanax online
Viagra without prescription uk
Levitra us
Where to buy cialis online
Where to buy phentermine cheap
Order xanax cod
Xanax 1mg side effects
2mg xanax no prescription
Buy generic phentermine online
Discount viagra usa
Cialis price
Cheap tramadol overnight delivery
Buy viagra online in ireland
Generic viagra super active
Cheap levitra no prescription
Where to buy propecia in canada
Cialis prices uk
Buy phentermine online no prescription
Xanax no rx
Canada pharmacy valium
Buy viagra online in australia
Generic xanax
Buy cialis online from canada
Order viagra without prescription
Cheap cialis viagra
Levitra online
Buy valium cheap online
Generic propecia
Tramadol online no prescription overnight
Online valium without prescription
Cialis purchase online
Purchase xanax
Real phentermine without prescription
Get tramadol prescription
Xanax 0.5 mg
Fedex tramadol
Buy xanax overnight
Low price cialis
Brand viagra cheap
Buy phentermine 37.5mg online
Phentermine hcl without prescription
Purchase viagra online without prescription
Buy viagra australia
Viagra pharmacy uk
Viagra canada online
Tramadol medication
Order tramadol online overnight
Phentermine hcl no prescription
Buy cialis uk
Viagra online without prescription reviews
Levitra samples
Propecia 1mg generic
Propecia uk pharmacy
Buy phentermine 37.5mg pills
Buy generic valium online
Propecia best prices
Brand name cialis
Cheap 37 5 phentermine