New topics: Your Pet, IOU, Baby IQ, The Poisons, Birther II, Games, Future Power

Welcome to the Tech Space!

Do you like Books?

Skip to end of metadata
Go to start of metadata

What are Dynamic classes in Actionscript?

  • Basically same idea as in perl where an object is a hash, where keys are the names of properties, and the values are the field values, or function pointers.
  • More memory overhead than sealed classes.
    • More info:
      • http://flexblog.faratasystems.com/2006/10/02/actionscript-3-dynamic-classes - you can dynamically add only public properties and methods. Of course, nothing comes for free and sealed classes are a bit more efficient in terms of memory consumption, because they do not need to create a hash table to store the properties and methods that are unknown during compilation. Another obvious restriction is that dynamically added functions can’t access private members of the dynamic class.
        • Examples:
          dynamic class Person {
          var name:String;
          }
          

          Now let’s add dynamically two variables name and age and the function printme() to the object of type Person:

          Person p= new Person();
          p.name=”Joe”;
          p.age=25;
          p.printMe = function () {
          trace (p.name, p.age);
          }
          p.printMe(); // Joe 25
          

          In AS3, any function can be attached to a dynamically created property of a dynamic object, for example

          function calcTax():Number {…}
          
          var myObject:SomeObject = new SomeObject();
          myObject.tax=calcTax; //add the tax property and attach the function calcTax()
          var myTax=myObject.tax();
          

          The delete operator destroys the property of an object and makes it eligible for garbage collection:

          delete calcTax();
          myTax=myObject.tax() // generates an error
          
      • Adobe Help for AS 3.0 - Dynamic Classes
        • Example of adding function to a dynamic class
          myProtean.traceProtean = function () 
          { 
              trace(myProtean.privateGreeting); // undefined 
              trace(myProtean.publicGreeting); // hello 
          }; 
          myProtean.traceProtean();
          
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.