通过单击更改舞台上对象的位置 - ActionScript 3

发布于 2024-12-13 08:12:17 字数 91 浏览 0 评论 0原文

我在舞台上有一些主持人,我希望通过点击他们来改变主持人的状态。例如,如果我单击 mc1,然后单击 mc2,那么它们应该更改位置。 有什么想法怎么做吗? 谢谢您的宝贵时间

I have somme mc's on the stage an I want thatto change on mc with antoher by clicking on them. For example if I click on mc1 and than on mc2 than they schould change the positions.
any ideea how o do that?
thank you for your time

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

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

发布评论

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

评论(1

迷你仙 2024-12-20 08:12:17

您需要为影片剪辑创建一个单击事件,并将其记录在单击了哪个影片剪辑的变量上,然后当单击第二个影片剪辑时,只需交换它们的位置即可。我将给您一段应该可以工作并且足以教您如何完成的代码片段。

import flash.events.MouseEvent;
// Variable that will be used to store the 1st clicked MC
var lastClickedSwapMC;

//First we define the function to be called
function clickEventSwapMcs(evt : MouseEvent) {
    // Verify if a mc wasn't previously clicked
    if(lastClickedSwapMC == null) {
        // If it wasn't, it's the 1st time, so store the MC that was clicked
        lastClickedSwapMC = evt.currentTarget;
    } else {
        // If it was, we just need to swap the positions of the stored one with the one just clicked
        var savedX : Number = evt.currentTarget.x;
        var savedY : Number = evt.currentTarget.y;
        evt.currentTarget.x = lastClickedSwapMC.x;
        evt.currentTarget.y = lastClickedSwapMC.y;
        lastClickedSwapMC.x = savedX;
        lastClickedSwapMC.y = savedY;
        //After swaping their position, we clear the last clicked MC
        lastClickedSwapMC = null;
    }
}

//Now we register the click event on them so it calls the function
mc1.addEventListener(MouseEvent.CLICK, clickEventSwapMcs);
mc2.addEventListener(MouseEvent.CLICK, clickEventSwapMcs);

You need to have a click event for the movieclip, and record it on a variable which movieclip was clicked, and then when the 2nd one is clicked, you just swap their positions. I'll give you a snippet of code that should work and should be enough to teach you how it's done.

import flash.events.MouseEvent;
// Variable that will be used to store the 1st clicked MC
var lastClickedSwapMC;

//First we define the function to be called
function clickEventSwapMcs(evt : MouseEvent) {
    // Verify if a mc wasn't previously clicked
    if(lastClickedSwapMC == null) {
        // If it wasn't, it's the 1st time, so store the MC that was clicked
        lastClickedSwapMC = evt.currentTarget;
    } else {
        // If it was, we just need to swap the positions of the stored one with the one just clicked
        var savedX : Number = evt.currentTarget.x;
        var savedY : Number = evt.currentTarget.y;
        evt.currentTarget.x = lastClickedSwapMC.x;
        evt.currentTarget.y = lastClickedSwapMC.y;
        lastClickedSwapMC.x = savedX;
        lastClickedSwapMC.y = savedY;
        //After swaping their position, we clear the last clicked MC
        lastClickedSwapMC = null;
    }
}

//Now we register the click event on them so it calls the function
mc1.addEventListener(MouseEvent.CLICK, clickEventSwapMcs);
mc2.addEventListener(MouseEvent.CLICK, clickEventSwapMcs);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文