JS2 and LZX syntax / instantiation

View: New views
4 Messages — Rating Filter:   Alert me  

JS2 and LZX syntax / instantiation

by Raju Bitter-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

Here's a simple JS2 class I wrote for testing. What would be the exact LZX
representation be? I'm trying do better understand instantiation of LZX
based classes and JS2 based classes. Either I made a mistake or I see some
differences for classes I port from LZX to JS2 syntax.

<library>

  <!-- testclassjs2, want to see how JS2 compares to LZX.
  -->

  <interface name="testclassjs2" extends="node">
   
    <!--- A test attribute.
          @type String
          @access private
    -->
    <attribute name="src" value="" type="string"/>

  </interface>

  <!-- these methods are shared across runtimes -->
  <script when="immediate"><![CDATA[
    mixin Testclassjs2Shared {
        function Testclassjs2Shared ( parent:LzView? = null , attrs:Object?
= null , children:Array? = null, instcall:Boolean  = false) {
            super(parent, attrs, children, instcall);
        }
    }
  ]]></script>

  <script when="immediate"><![CDATA[

    // Classes that implement an interface must obey the LZX
    // tag->class mapping convention
    dynamic class $lzc$class_testclassjs2 extends LzView with
Testclassjs2Shared {

        // Next two are part of the required LFC tag class protocol
        static var tagname = 'testclassjs2';
        static var attributes = new LzInheritedHash(LzView.attributes);
        static var uid = 0;
       
        var src = "";
       
        var onsrc = LzDeclaredEvent;

        override function construct(parent,args) {
            super.construct(parent, args);
            Debug.write("constructor");
            new LzDelegate( this , "_oninit" , this , "oninit" );
            new LzDelegate( this, "_onSrc", this, "onsrc");
        }

        function $lzc$class_testclassjs2(parent, attrs, children, async) {
            super(parent, attrs, children, async);
        }

        override function init() {
            super.init();
            Debug.write(this, "init()");
        }
       
        function _oninit(ignore) {
            Debug.write(this, "_oninit()");
        }
         
        function _setSrc(value) {
            Debug.write(this, "_setSrc()", value);
            this.src = value;
        }
       
        function $lzc$set_src(value) {
            Debug.write(this, "$lzc$set_src()", value);
            this._setSrc(value);
            this.onsrc.sendEvent(this);
        }

        function _onSrc (evt) {
            Debug.write(this, "_onSrc()", evt);
        }
       

    } // End of testclassjs2
    lz[$lzc$class_testclassjs2.tagname] = $lzc$class_testclassjs2;
  ]]></script>
</library>

Thanks,
Raju



Re: JS2 and LZX syntax / instantiation

by David Temkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Raju,

Is there a reason you are writing a class in JS2 form rather than LZX  
form?  Did you run into a limitation of what you could declare in LZX,  
or are you just trying to understand how the script and LZX forms  
relate?

- D.

On Jul 20, 2008, at 4:06 PM, Raju Bitter wrote:

> Hi all,
>
> Here's a simple JS2 class I wrote for testing. What would be the  
> exact LZX
> representation be? I'm trying do better understand instantiation of  
> LZX
> based classes and JS2 based classes. Either I made a mistake or I  
> see some
> differences for classes I port from LZX to JS2 syntax.
>
> <library>
>
>  <!-- testclassjs2, want to see how JS2 compares to LZX.
>  -->
>
>  <interface name="testclassjs2" extends="node">
>
>    <!--- A test attribute.
>          @type String
>          @access private
>    -->
>    <attribute name="src" value="" type="string"/>
>
>  </interface>
>
>  <!-- these methods are shared across runtimes -->
>  <script when="immediate"><![CDATA[
>    mixin Testclassjs2Shared {
>        function Testclassjs2Shared ( parent:LzView? = null ,  
> attrs:Object?
> = null , children:Array? = null, instcall:Boolean  = false) {
>            super(parent, attrs, children, instcall);
>        }
>    }
>  ]]></script>
>
>  <script when="immediate"><![CDATA[
>
>    // Classes that implement an interface must obey the LZX
>    // tag->class mapping convention
>    dynamic class $lzc$class_testclassjs2 extends LzView with
> Testclassjs2Shared {
>
>        // Next two are part of the required LFC tag class protocol
>        static var tagname = 'testclassjs2';
>        static var attributes = new LzInheritedHash(LzView.attributes);
>        static var uid = 0;
>
>        var src = "";
>
>        var onsrc = LzDeclaredEvent;
>
>        override function construct(parent,args) {
>            super.construct(parent, args);
>            Debug.write("constructor");
>            new LzDelegate( this , "_oninit" , this , "oninit" );
>            new LzDelegate( this, "_onSrc", this, "onsrc");
>        }
>
>        function $lzc$class_testclassjs2(parent, attrs, children,  
> async) {
>            super(parent, attrs, children, async);
>        }
>
>        override function init() {
>            super.init();
>            Debug.write(this, "init()");
>        }
>
>        function _oninit(ignore) {
>            Debug.write(this, "_oninit()");
>        }
>
>        function _setSrc(value) {
>            Debug.write(this, "_setSrc()", value);
>            this.src = value;
>        }
>
>        function $lzc$set_src(value) {
>            Debug.write(this, "$lzc$set_src()", value);
>            this._setSrc(value);
>            this.onsrc.sendEvent(this);
>        }
>
>        function _onSrc (evt) {
>            Debug.write(this, "_onSrc()", evt);
>        }
>
>
>    } // End of testclassjs2
>    lz[$lzc$class_testclassjs2.tagname] = $lzc$class_testclassjs2;
>  ]]></script>
> </library>
>
> Thanks,
> Raju
>
>


Re: JS2 and LZX syntax / instantiation

by P T Withington :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not sure exactly what you are asking here, but we don't support  
mixin's at the LZX level yet, so there is no way to do exactly what  
you are doing in "pure" LZX.

On 2008-07-20, at 19:06EDT, Raju Bitter wrote:

> Hi all,
>
> Here's a simple JS2 class I wrote for testing. What would be the  
> exact LZX
> representation be? I'm trying do better understand instantiation of  
> LZX
> based classes and JS2 based classes. Either I made a mistake or I  
> see some
> differences for classes I port from LZX to JS2 syntax.
>
> <library>
>
>  <!-- testclassjs2, want to see how JS2 compares to LZX.
>  -->
>
>  <interface name="testclassjs2" extends="node">
>
>    <!--- A test attribute.
>          @type String
>          @access private
>    -->
>    <attribute name="src" value="" type="string"/>
>
>  </interface>
>
>  <!-- these methods are shared across runtimes -->
>  <script when="immediate"><![CDATA[
>    mixin Testclassjs2Shared {
>        function Testclassjs2Shared ( parent:LzView? = null ,  
> attrs:Object?
> = null , children:Array? = null, instcall:Boolean  = false) {
>            super(parent, attrs, children, instcall);
>        }
>    }
>  ]]></script>
>
>  <script when="immediate"><![CDATA[
>
>    // Classes that implement an interface must obey the LZX
>    // tag->class mapping convention
>    dynamic class $lzc$class_testclassjs2 extends LzView with
> Testclassjs2Shared {
>
>        // Next two are part of the required LFC tag class protocol
>        static var tagname = 'testclassjs2';
>        static var attributes = new LzInheritedHash(LzView.attributes);
>        static var uid = 0;
>
>        var src = "";
>
>        var onsrc = LzDeclaredEvent;
>
>        override function construct(parent,args) {
>            super.construct(parent, args);
>            Debug.write("constructor");
>            new LzDelegate( this , "_oninit" , this , "oninit" );
>            new LzDelegate( this, "_onSrc", this, "onsrc");
>        }
>
>        function $lzc$class_testclassjs2(parent, attrs, children,  
> async) {
>            super(parent, attrs, children, async);
>        }
>
>        override function init() {
>            super.init();
>            Debug.write(this, "init()");
>        }
>
>        function _oninit(ignore) {
>            Debug.write(this, "_oninit()");
>        }
>
>        function _setSrc(value) {
>            Debug.write(this, "_setSrc()", value);
>            this.src = value;
>        }
>
>        function $lzc$set_src(value) {
>            Debug.write(this, "$lzc$set_src()", value);
>            this._setSrc(value);
>            this.onsrc.sendEvent(this);
>        }
>
>        function _onSrc (evt) {
>            Debug.write(this, "_onSrc()", evt);
>        }
>
>
>    } // End of testclassjs2
>    lz[$lzc$class_testclassjs2.tagname] = $lzc$class_testclassjs2;
>  ]]></script>
> </library>
>
> Thanks,
> Raju
>
>


Parent Message unknown Re: JS2 and LZX syntax / instantiation

by Raju Bitter-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Re: [Laszlo-dev] JS2 and LZX syntax  / instantiation David,

Yes, it's not possible to import AS3 packages/classes with the syntax I know.

<canvas>        <script when="immediate">        #passthrough (toplevel:true) {              import flash.net.NetConnection;        }#    </script>        <class name="testclass1" extends="node">        <attribute name="_nc" type="expression" value="null" />                <method name="init">            super.init();            this.nc = new NetConnection();        </method>    </class>     </canvas> <!-- compiles to AS3 as: package { dynamic class $lzc$class_testclass1 extends LzNode { static var tagname = "testclass1";
static var attributes = new LzInheritedHash(LzNode.attributes);
var _nc;override function init () { super.init(); this.nc = new NetConnection() }
function $lzc$class_testclass1 ($lzc$parent:LzNode? = null, $lzc$attrs:Object? = null, $lzc$children:Array? = null, $lzc$async:Boolean = false) { super($lzc$parent, $lzc$attrs, $lzc$children, $lzc$async) }LzNode.mergeAttributes({_nc: null}, $lzc$class_testclass1.attributes);} } -->

$passthrough (toplevel:true) { }# only seems to work inside classes written in JS2 syntax. Is there any other way to put import statements into LZX code? I tried using <script> tags with if ($sw9) { $passthrough (toplevel:true) { }# }, like

    <script when="immediate">
      #passthrough (toplevel:true) {
        import flash.net.NetConnection;
      }#
    </script>

But that doesn’t work, either. The only working code I found and your experts pointed me to was drawview.lzx, which’s syntax I’m copying.

Best,
Raju
LightInTheBox - Buy quality products at wholesale price