Actionscript 3 获取错误1119:通过静态类型类的引用访问可能未定义的属性
我试图在动画加载后立即隐藏符号(栅格图像)。 目前我收到了错误,E:\Burger Game\DragandDrop\Dragable.as,第4行,第8列1119:通过静态类型类的引用访问可能未定义的属性。正如你可能知道的那样,我对flash是新手Actionscript 3 获取错误1119:通过静态类型类的引用访问可能未定义的属性,actionscript-3,flash-cs5,Actionscript 3,Flash Cs5,我试图在动画加载后立即隐藏符号(栅格图像)。 目前我收到了错误,E:\Burger Game\DragandDrop\Dragable.as,第4行,第8列1119:通过静态类型类的引用访问可能未定义的属性。正如你可能知道的那样,我对flash是新手 package DragandDrop { Grill.visible=false; import flash.display.MovieClip; import flash.events.MouseEvent; i
package DragandDrop
{
Grill.visible=false;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
public class Dragable extends MovieClip
{
protected var homePos:Point;
var totalToBowl:int =3;
var i:int = 0;
public function Dragable ()
{
homePos=new Point( x, y);
buttonMode =true;
addEventListener ( MouseEvent.MOUSE_DOWN, move);
}
//egg functions
protected function move(event:MouseEvent) :void
{
parent.addChild(this);
startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stageUp)
}
//item drop function
protected function stageUp(event:MouseEvent):void
{
stopDrag();
if (event.target.dropTarget != null &&dropTarget.parent.name == "Bowl")
{
scaleX=scaleY=0;
alpha=0.5;
y= stage.stageHeight-height -700;
x=stage.stageWidth-width- 1400;
buttonMode=false;
removeEventListener(MouseEvent.MOUSE_DOWN, stageUp)
i++
}if (i == totalToBowl){
i=10
trace(i);
event.target.dropTarget.visible = false;
}
if (i==10 )
{
dropTarget.parent.visible = false;
}else{
returnToHome();
}
}
protected function returnToHome():void
{
x = homePos.x;
y= homePos.y;
}
}
知道我为什么会犯这个错误吗
任何帮助都将不胜感激。
非常感谢,
Rob有两个问题:
Grill
是一个类,但您似乎试图将其作为一个实例来使用。这是它在像您这样使用时所期望看到的:
public class Grill extends MovieClip {
public static var visible:Boolean;
}
但更可能的是,您需要做的是使用实例,而不是类本身:
var g:Grill = new Grill();
g.visible = false;
如果该类链接到时间轴实例,则必须使用为其指定的实例名称(并确保实例名称与任何类名不冲突,或者使用getChildByName
)public function Dragable ()
{
homePos=new Point( x, y);
buttonMode =true;
addEventListener ( MouseEvent.MOUSE_DOWN, move);
//addedToStage is the best equivalent of when timeline code would run
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void {
//where grillinstance is the instance name of your grill
grillInstance.visible = false;
}
现在,假设您在时间线上链接了这个类,该时间线上有一个Grill实例。如果这是一个不正确的假设,请通过注释或更新您的问题来澄清。听起来像是
Grill
是一个链接到符号的类,但visible
是一个实例属性,而不是类属性(static
)。与可拖动的相关的栅格实例在哪里?Dragable
是您的文档类吗?@Rob-您找到解决方案了吗?实际上,您可以将代码放在类中函数之外,它会得到(示例将其包装在{}
中,但这不是必需的)。这样做的理由很少(如果有的话),但OP的代码实际上是有效的,只是不是他们的意思。否则这是一个很好的答案,是的,这是假设它不是静态代码。但这是一个很好的澄清点。