[Laszlo-dev] setters in swf9

Philip Romanik promanik at laszlosystems.com
Fri Feb 1 08:37:58 PST 2008


Hi Henry,

There is code in the data classes that specify setters. For example, 
this code is in LzDataText.lzs:

setters.data = "setData";


Can this be done in a static initializer? The original traits use 
this method to install setters. The code compiles in swf9 but I don't 
know if it works. For example, in the class LzMiniNode_DataNode_DOM 
(my manually instantiated class):

     static function initialize (prototype) {
       // There will be no setters property in the trait prototype,
       // (and you don't want one there! as it would shadow the one
       // from LzNode) but it will be there after LzNode.initialize
       // runs
       if (prototype.hasOwnProperty('setters')) {
         // since you can't assign directly to these slots...
         // until LzNode.initialize has run
         prototype.setters.attributes = "setAttrs";
         prototype.setters.childNodes = "setChildNodes";
         prototype.setters.nodeName = "setNodeName";
         // Shouldn't be directly settable
         prototype.setters.ownerDocument = "setOwnerDocument";
       }
     }



>Yes, look at LaszloView.js or LzText.js for examples what I've been 
>doing. I declare static class vars like  this, which make copies of 
>the superclass's setters vars
>
>     static var getters = new LzInheritedHash(LFCNode.getters);
>     static var defaultattrs = new LzInheritedHash(LFCNode.defaultattrs);
>     static var options = new LzInheritedHash(LFCNode.options);
>     static var setters = new LzInheritedHash(LFCNode.setters);
>     static var __LZdelayedSetters:* = new 
> LzInheritedHash(LFCNode.__LZdelayedSetters);
>     static var earlySetters:* = new LzInheritedHash(LFCNode.earlySetters);
>
>And the base constructor in LFCNode (which is the 'static' version 
>of LzNode, see core/LzNode.js) automatically copies these class vars 
>to the corresponding instance vars when a node is constructed.
>
>
>Note, there's an issue at runtime that comes up if you have code 
>which tries to set arbitrary properties on a class which have not 
>been declared at compile time. To allow this, the class has to be 
>declared 'dynamic'.
>Eventually we're going to make <attribute> declarations cause 
>compile-time declarations of instance vars, but we don't do that yet 
>so I've been doing the following thing:
>
>I have an idiom I am using in LzNode and LzView whereby I have an 
>"internal" class, LFCNode, or LFCView, which is not declared 
>'dynamic', and then I have a kind of 'wrapper' class which I declare 
>as 'dynamic', (e.g., LzNode, LzView). This is to get the (hoped for) 
>benefit of the as3 compiler making more efficient code 
>for  accessors to methods and instance vars of  these superclasses 
>because they are not declared dynamic.
>
>For the data classes, I think they can all just be left as they are, 
>and not declare them dynamic, and see if we can get them to compile.
>For now if something subclasses LzNode, just leave it doing that.
>Eventually we may want to make that subclass LFCNode instead. At 
>runtime, if we discover that there are classes where code which is 
>adding properties dynamically at runtime, we can see about making a 
>'dynamic' subclass for those classes, or just declare them dynamic, 
>or something.
>
>
>
>
>On Fri, Feb 1, 2008 at 10:27 AM, Philip Romanik 
><<mailto:promanik at laszlosystems.com>promanik at laszlosystems.com> wrote:
> > Hi Henry,
> >
> >  What is the "new" way to handle setters in swf9? The solution you're
> > using in LaszloView looks like,
> >
> >  static var setters = new LzInheritedHash(LFCNode.setters);  ...
> >  LFCView.setters.clip = -1;
> >
> >
> >  Should I use this same approach with the files I'm porting?
> >
> >  Thanks!
> >
> >  Phil
> >
> >
>
>
>
>--
>Henry Minsky
>Software Architect
><mailto:hminsky at laszlosystems.com>hminsky at laszlosystems.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20080201/55bf9fd4/attachment-0001.html


More information about the Laszlo-dev mailing list