AS3>未找到类型或不是编译时常量:事件

发布于 2024-12-21 20:00:22 字数 2637 浏览 0 评论 0原文

有人可以告诉我这段代码有什么问题吗?

1046: Type was not found or was not a compile-time constant: Event.

private function contactListener(e:Event)
    {
        if (simContacts.isCurrentContact(winBox))
        {
            // Won.
            trace ('You won!');
        }
    }

完整代码:

package  {

import flash.display.MovieClip;
import com.actionsnippet.qbox.*;  
import flash.events.MouseEvent;
import com.actionsnippet.qbox.QuickContacts;

[SWF(width = 600, height = 600, frameRate = 60)]  

public class LuckyHit extends MovieClip {

    public var sim:QuickBox2D;
    var winBox:QuickObject;
    var looseBox:QuickObject;
    var gameBall:QuickObject;
    var simContacts:QuickContacts;

    /**
     * Constructor
     */
    public function LuckyHit()
    {
        sim = new QuickBox2D(this);
        simContacts = sim.addContactListener();
        simContacts.addEventListener(QuickContacts.ADD, contactListener);
        //sim.createStageWalls();
        winBox = sim.addBox({x:5,y:600/30, width:300/30, height:10/30, density:0});
        looseBox = sim.addBox({x:15,y:600/30, width:300/30, height:10/30, density:0});



        // make obstacles 
        for (var i:int = 0; i<(stage.stageWidth/50); i++){ 
        //End
             sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0});
             sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0});

        //Mid End

              sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0});


        //Middle Start
             sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0});
             sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0});
             sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0});
             sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0});

        }

        sim.start();


        stage.addEventListener(MouseEvent.CLICK, _clicked);
    }

    /**
     * ..
     * @param e MouseEvent.CLICK
     */

    private function _clicked(e:MouseEvent)
    {
        gameBall = sim.addCircle({x:(mouseX/30), y:(1), radius:0.25, density:5});


    }

    private function contactListener(e:Event)
    {
        if (simContacts.isCurrentContact(winBox))
        {
            // Won.
            trace ('You won!');
        }
    }


}

}

Can somebody tell me what's wrong with this code?

1046: Type was not found or was not a compile-time constant: Event.

private function contactListener(e:Event)
    {
        if (simContacts.isCurrentContact(winBox))
        {
            // Won.
            trace ('You won!');
        }
    }

Full Code:

package  {

import flash.display.MovieClip;
import com.actionsnippet.qbox.*;  
import flash.events.MouseEvent;
import com.actionsnippet.qbox.QuickContacts;

[SWF(width = 600, height = 600, frameRate = 60)]  

public class LuckyHit extends MovieClip {

    public var sim:QuickBox2D;
    var winBox:QuickObject;
    var looseBox:QuickObject;
    var gameBall:QuickObject;
    var simContacts:QuickContacts;

    /**
     * Constructor
     */
    public function LuckyHit()
    {
        sim = new QuickBox2D(this);
        simContacts = sim.addContactListener();
        simContacts.addEventListener(QuickContacts.ADD, contactListener);
        //sim.createStageWalls();
        winBox = sim.addBox({x:5,y:600/30, width:300/30, height:10/30, density:0});
        looseBox = sim.addBox({x:15,y:600/30, width:300/30, height:10/30, density:0});



        // make obstacles 
        for (var i:int = 0; i<(stage.stageWidth/50); i++){ 
        //End
             sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0});
             sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0});

        //Mid End

              sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0});
              sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0});


        //Middle Start
             sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0});
             sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0});
             sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0});
             sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0});

        }

        sim.start();


        stage.addEventListener(MouseEvent.CLICK, _clicked);
    }

    /**
     * ..
     * @param e MouseEvent.CLICK
     */

    private function _clicked(e:MouseEvent)
    {
        gameBall = sim.addCircle({x:(mouseX/30), y:(1), radius:0.25, density:5});


    }

    private function contactListener(e:Event)
    {
        if (simContacts.isCurrentContact(winBox))
        {
            // Won.
            trace ('You won!');
        }
    }


}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-12-28 20:00:22

您需要导入 Event 类:

import flash.events.Event;

You need to import the Event class:

import flash.events.Event;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文