0

在我开始学习 AS3 后,我遇到了很多错误(尝试将十字准线动态添加到舞台上,而不是使用鼠标光标进行射击游戏):

Main.as, Line 13 1180: Call to a possibly undefined method addChild.
Main.as, Line 13 1120: Access of undefined property crosshair.
Main.as, Line 20 1120: Access of undefined property stage.
Main.as, Line 20 1120: Access of undefined property moveCursor.
4

1 回答 1

3

你的类中没有构造函数。

尝试这个 :

package  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    public class Main extends MovieClip {

    public var crosshair:crosshair_mc;


    public function Main()
    {
        //This creates a new instance of the cursor movie clip and adds it onto
        //the stage using the addChild method.
        crosshair = new crosshair_mc();
        addChild(crosshair);

        //Hides the default cursor on the stage so it will not be shown.
        Mouse.hide();

        //Adds an event listener onto the stage with the enter frame event which
        //repeatedly executes the moveCursor function.
        stage.addEventListener(Event.ENTER_FRAME, moveCursor);
    }

    //This function set the x & y positions of the custom cursor to the x & y positions
    //of the default cursor.
    function moveCursor(event:Event) 
    {
      crosshair.x=mouseX;
      crosshair.y=mouseY;
     }
   }
}
于 2013-04-23T00:55:55.053 回答