[英]Migrating from ActionScript 2 to ActionScript 3
我正在嘗試將其他人的Flash應用程序轉換為ActionScript3。在此之前,我從未處理過ActionScript。 我嘗試執行錯誤消息告訴我的操作,但它們使我陷入困境。 因此,這是情況的簡化版本。 我在基本文件夾中有一個動作腳本,如下所示:
class IF12345
{
var a0:controls.Button;
var a1:controls.TextArea;
var a2:controls.TextInput;
}
現在,控件如下所示:
dynamic class mx.controls.Button extends mx.controls.SimpleButton
{
var enabled;
function Button()
{
}
function draw()
{
}
var borderW = 1;
}
我得到的第一個錯誤是它抱怨動作腳本必須具有一個外部可見的類,因此我在基本文件中的類中添加了public。 然后它說沒有包就不能有一個公共類,所以我把它包裝在一個包中。
之后,它說動作腳本必須具有一個控件的外部可見類,因此我在控件類中添加了public。 當然,然后它抱怨需要放在一個包中,但是當我將控件類放在一個包中時,它說我沒有嵌套的包。 所以在這一點上我不知道該怎么辦?
看起來您似乎有些混亂,但是我看到的主要一點是,您似乎正在嘗試使類名包含整個包。 我認為您想要的一個可行的示例是:
package controls
// ^^^^^^^^ The controls package is defined here, not when providing the
// class name like in your example.
{
import flash.display.SimpleButton;
// ^^^^^^^^^^^^^ In ActionScript 3, SimpleButton is in the
// flash.display package, and needs to be imported with an
// import statement above the class definition.
public class Button extends SimpleButton
// ^^^^^^ We only use the class name here. You can do the fully
// qualified class name for the extended class, but the
// import statement is cleaner and makes that unnecessary
// except for in uncommon circumstances.
{
private var enabled:Boolean = false;
private var borderW:int = 1;
public function Button()
{
// Constructors must be public.
}
public function draw()
{
//
}
}
}
和你的其他班級:
package
{
import controls.Button;
// ^^^^^^^^^^^^^^^ Need to import your above Button class.
public class IF12345
{
public var a0:Button;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.