由于某种原因,未定义的 MovieClip 数组 (Actionscript 3.0)
我只是想做一款“二消”游戏。我刚刚开始这样做,因为我是初学者,所以我试图了解数组是如何工作的。因此,我编写了这个简单的程序:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var Ar:Array = [];
Ar[0] = A;
Ar[1] = B;
Ar[2] = C;
public function Main()
{
for( var i = 0; i < 3; i++ )
{
Ar.buttonMode = true;
Ar[i].addEventListener( MouseEvent.MOUSE_OVER, MouseOverAct );
Ar[i].addEventListener( MouseEvent.MOUSE_OUT, MouseOutAct );
}
}
public function MouseOverAct( mouseEvent:MouseEvent ):void
{
mouseEvent.target.alpha = 0.1;
}
public function MouseOutAct( mouseEvent:MouseEvent ):void
{
mouseEvent.target.alpha = 1.0;
}
}
}
但是,在声明数组并尝试将 MovieClip(已经在舞台上,实例名称为 A、B、C)放入其中后,我收到“未定义的属性”错误。我尝试使用 Ar.push() 来纠正它,但效果不佳。有人可以帮助我吗?
I am simply trying to do one of those "match-2" games. I just started doing it, and since I am a beginner, I am trying to understand how Arrays work. Therefore I wrote this simple program:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var Ar:Array = [];
Ar[0] = A;
Ar[1] = B;
Ar[2] = C;
public function Main()
{
for( var i = 0; i < 3; i++ )
{
Ar.buttonMode = true;
Ar[i].addEventListener( MouseEvent.MOUSE_OVER, MouseOverAct );
Ar[i].addEventListener( MouseEvent.MOUSE_OUT, MouseOutAct );
}
}
public function MouseOverAct( mouseEvent:MouseEvent ):void
{
mouseEvent.target.alpha = 0.1;
}
public function MouseOutAct( mouseEvent:MouseEvent ):void
{
mouseEvent.target.alpha = 1.0;
}
}
}
However, after declaring the array and trying to put the MovieClips (which are already on the stage, with instance names A, B, C) inside it I get an "Undefined property" error. I have tried to correct it using Ar.push(), but it doesn't work as well. Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这
是一个不正确的代码。您应该在变量声明或任何方法中初始化实例属性(在您的情况下是数组)。可以在静态块中初始化静态属性。我认为这个关于静态块初始化的链接会对您有所帮助。所以你应该做:
或者
This
is an incorrect code. You should initialize an instance property (in your case the array) either at variable declaration or at any method. It is possible to initialize a static protperties in static block. I think this link about static block initialisation would helpfull for you. So you should do either:
or