2 个具有相同实例名称的影片剪辑

发布于 2024-12-29 04:10:24 字数 614 浏览 7 评论 0原文

我在时间线上有同一个影片剪辑的 2 个副本,并且我需要它们都执行完全相同的操作,所以我想我应该给它们相同的实例名称。

我在舞台上有一个事件侦听器,用于侦听鼠标单击,然后使用 switch 语句检查单击的内容,但 switch 语句仅拾取影片剪辑的一个实例,另一个实例作为默认值出现。

我主要要问的是,是否可以在时间轴上使用相同的实例名称制作影片剪辑?

public function Main() {
    stage.addEventListener(MouseEvent.CLICK, doStuff);
}

public function doStuff(e:MouseEvent):void {
    switch (e.target) {
        case myMC1 :
            //do stuff
            break;
        case myMC2 :
            //do stuff
            break;
        case myMC3 :
            //do stuff
            break;
        default :
            //do stuff
    }
}

I have 2 copys of the same Movieclip on the timeline and I need them both to do the exact same thing, so I figured I'd give them the same instance name.

I have an event listener on the stage that listens for a mouse click and then checks what has been clicked using a switch statment, but the switch statment only picks up one instance of the movieclip, the other one comes up as the default.

Mainly what i'm asking is, is it possible to have to movieclips on the timeline with the same instance name?

public function Main() {
    stage.addEventListener(MouseEvent.CLICK, doStuff);
}

public function doStuff(e:MouseEvent):void {
    switch (e.target) {
        case myMC1 :
            //do stuff
            break;
        case myMC2 :
            //do stuff
            break;
        case myMC3 :
            //do stuff
            break;
        default :
            //do stuff
    }
}

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

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

发布评论

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

评论(2

翻身的咸鱼 2025-01-05 04:10:24

为实例指定两个不同的名称(永远不要对两个对象使用相同的名称,真的:))并以这种方式更改 switch 语句:

 public function doStuff(e:MouseEvent):void {
switch (e.target) {
    case myMC1 :
    case myMC2 :
        //do stuff
        break;
    case myMC3 :
        //do stuff
        break;
    default :
        //do stuff
}
}

通过以这种方式格式化它,您可以为两种不同的情况执行相同的代码

Give the instances two different names (NEVER USE THE SAME NAME FOR TWO OBJECT, REALLY :)) and change the switch statement this way:

 public function doStuff(e:MouseEvent):void {
switch (e.target) {
    case myMC1 :
    case myMC2 :
        //do stuff
        break;
    case myMC3 :
        //do stuff
        break;
    default :
        //do stuff
}
}

By formatting it this way, you can execute the same code for two different cases

不必了 2025-01-05 04:10:24

请改用 e.currentTarget。
e.target 将为您提供调度事件的对象,该对象可能是 MovieCLip 的子级

Use e.currentTarget instead.
e.target will give you the object that dispatched the event which could be a child of your MovieCLip

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