编程对象:方法、参数与事件处理
在编程中,方法、参数和事件处理是非常重要的概念。下面将详细介绍如何使用基本方法、创建方法参数,以及理解事件和事件监听器。
使用基本方法
首先,我们来看如何在程序中使用一个非常简单的方法。以下是具体步骤:
1. 创建一个新的AS3.0项目。
2. 在编辑器窗口中输入以下代码:
package
{
import flash.display.Sprite;
public class MethodWithoutParameters extends Sprite
{
public function MethodWithoutParameters()
{
displayText();
}
public function displayText():void
{
trace("This is text from the function definition");
}
}
}
- 编译程序,你将看到以下跟踪消息显示:
This is text from the function definition
这个程序的结构很重要。方法调用 displayText() 位于程序的构造函数块内。这是因为构造函数方法内的任何内容在程序首次启动时会立即运行。 displayText
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



