正 文

探索Laszlo的类、属性及事件


www.7dspace.com  更新日期:2005-10-1 3:59:41  七度空间


  探索属性及事件及联系

  范例代码现在开始进一步探索属性与事件之间的联系.被用来测试alert的按钮也可以用来设定此前定义的属性.我想要展示的是设定这些属性如何触发相应的onchange方法.

  以下编码是一个方法,respondToButton(), 将在showAlert按钮按下时被调用.

<canvas width="800" debug="true">
<debug x="450" y="0" height="300"/>
<class name="test">
        <attribute name="a1" type="string"/>
        <attribute name="b1"/>
</class>
<!--Instantiating a class-->
<test name="testInstance">
        <!--Demonstrating an onchange for attribute event-->
     
        <method event="ona1" name="ona1Method">
                Debug.write("hey this works");
        </method>
     
</test>

<!-- Simulating an alert -->
<!-- A modal alert dialog -->
<alert name="myalert" width="100" y="100">
   hi - initial text
</alert>

<!-- A method to work the modal dialog -->
<method name="showAlert" args="displayText">
   canvas.myalert.setAttribute("text",displayText);
   canvas.myalert.open();
</method>

<!-- Testing the alert function -->
<button onclick="canvas.respondToButton()">Show Alert</button>
<method name="respondToButton" >
        //Prepare a string
        var somestring =
                "Hey, I am setting the a1 attributes value";

        //Write a debug to see it
        Debug.write(somestring);

        //Call the alert to see it
        showAlert(somestring);

        //Go ahead and set the attribute
        canvas.testInstance.setAttribute("a1",'satya');
        //The above will fire an event causing
        //"ona1Method" to execute.
        //You will see this in the debugger
</method>

</canvas>

6页,页码:[1]  [2] [3] [4] [5] [6] 

上一篇:用web.xml控制Web应用的行为
下一篇:Windows 2000绝版安全配置教程之初级篇
作者:Satya Komatineni  来源:onjava ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐