ActionScript 3.0和类帮助 [英] ActionScript 3.0 and Classes Help
问题描述
我对ActionScript 3.0中的面向对象编程相对较新。我设计了一些云,我试图通过类来控制云的移动。我使用的代码来自我在线的教程。我在flash中创建了两个场景(开始场景和主场景),我有一个名为Cloud.as的类。云开始在开始场景中运行良好但是一旦我按下开始按钮进入下一个场景,我就有了错误:
TypeError:错误#1009:无法访问null对象引用的属性或方法。
at Cloud / wrapCloud( )[Project\Jack_Crawford_System\Cloud.as:46]
在Cloud / onEnter()[Project\Jack_Crawford_System\Cloud.as:37]
任何人都可以告诉我该怎么办?主场景中没有代码
以下是Cloud.as的代码:
Hi, I am relatively new to object oriented programming in ActionScript 3.0..I designed some cloud and I am trying to control the movement of the cloud via a class. The code I have used is from a tutorial I followed online. I created two Scenes in flash (start scene and Main scene) and I have a class called Cloud.as..The cloud movements work fine in the start scene but once I hit the start button to go in the next scene, I am having an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Cloud/wrapCloud()[Project\Jack_Crawford_System\Cloud.as:46]
at Cloud/onEnter()[Project\Jack_Crawford_System\Cloud.as:37]
Can anyone please tell me what should I do? There is no code in the Main scene
Here is the code for the Cloud.as:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Cloud extends MovieClip
{
private var _cloudpixel:Number;
private var _halfCloudWidth:Number;
public function Cloud()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
_cloudpixel = -1;
_halfCloudWidth = this.width/2;
addEventListener(Event.ENTER_FRAME, onEnter);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onRemovedFromStage(event:Event): void
{
removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
private function onEnter(event:Event):void
{
this.x +=_cloudpixel;
wrapCloud();
}
private function wrapCloud():void
{
if (this.x + _halfCloudWidth<0)
{
this.x = stage.stageWidth + _halfCloudWidth;
}
}
}
}
谢谢!
Thank you!
推荐答案
问题出在wrapCloud()
方法,第46行:此
为空,或阶段
为空。
Hi,
The problem lies inwrapCloud()
method, line 46 : eitherthis
is null, orstage
is null.
这篇关于ActionScript 3.0和类帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!