We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

dan_mcweeney on 08/13/08


Tagged


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

THEPWN3R


ActiveRecord v0.2


Published in: ActionScript 3 


  1. package
  2. {
  3. import flash.utils.Proxy;
  4. import flash.utils.describeType;
  5. import flash.utils.getDefinitionByName;
  6. import flash.utils.getQualifiedClassName;
  7. import flash.utils.flash_proxy;
  8.  
  9. // import flash.utils.flash_proxy;
  10.  
  11. public dynamic class ActiveRecord extends Proxy
  12. {
  13. private static var functionsToAdd:Array = ["find_by_name","find_by_id","find_all"];
  14. protected static var methodFactory:DynamicMethodFactory;
  15. public function ActiveRecord()
  16. {
  17.  
  18. }
  19. public static function staticInitializer(klass:Class):void{
  20. var typeInfo:XML = describeType(klass);
  21. for each(var s:String in functionsToAdd){
  22. klass[s] = getMethod(typeInfo.@name,s);
  23. }
  24. }
  25. public static function getMethod(objectName:String,methodName:String):Function{
  26. return function(...args):Object{return endPoint(objectName,methodName,args);};
  27. }
  28. public static function endPoint(objectName:String,methodName:String,...args):Object{
  29. trace("You called: " + objectName + "." + methodName + "(" + args + ")");
  30. var klass:Class = getDefinitionByName(objectName) as Class;
  31. var o:ActiveRecord = new klass();
  32. return o;
  33. }
  34. flash_proxy override function callProperty(method: *, ...args): * {
  35. try {
  36. var clazz : Class = getDefinitionByName(getQualifiedClassName(this)) as Class;
  37. return clazz.prototype[method].apply(method, args);
  38. }
  39. catch (e : Error) {
  40. return methodMissing (method, args);
  41. }
  42. }
  43. protected function methodMissing(method : *, args : Array) : Object{
  44. throw( new Error("Method Missing"));
  45. return null;
  46. }
  47. }
  48. }

Report this snippet 

You need to login to post a comment.