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!