正 文

探索Laszlo的类、属性及事件


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


  注意,留意这个按钮是如何设置由test类声明的testInstance object的属性的.通常会犯一个错误,即在写LZX方法是在其方法名后加大括号,这是没有必要的。

  运行此实例,按下按钮将会显示出如图3所示

  图3 事件激活实例

  使用脚本代替方法

<canvas width="800" debug="true">
<debug x="450" y="0" height="300"/>

<!-- The previous respond method -->
<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>

<!-- Your method rewritten as a script -->
<script>
function respondToButtonUsingScript()
{
        var somestring =
            "Hey, I am setting the a1 attributes value";
        Debug.write(somestring);
        showAlert(somestring);
        canvas.testInstance.setAttribute("a1",'satya');
}
</script>
<!-- Button now calling the global script function -->
<button onclick="respondToButtonUsingScript()">
    Show Alert
</button>


<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>
</canvas>

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

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

热 点 导 读
特 别 推 荐