AS3 中的按钮充当带有鼠标事件的滚动?

发布于 2024-08-30 15:03:34 字数 635 浏览 5 评论 0原文

我是新来的,刚刚在谷歌上发现了这些论坛。

首先,如果有这样的主题,我想表示歉意,但我搜索了整个论坛,但没有找到任何可以解决我的问题的主题。

现在是重要的一件事。正如我在主题标题中所述,我需要一个执行此操作的 AS3 代码。这就是我想要的 完成。我的屏幕中央有一个 MC(图像),有两个按钮,一个在右边,一个在左边 那个MC的一边。我想在鼠标事件上向左或向右滚动(图像就像一个菜单),向下或向上滚动。 所以,我只想在按住鼠标按钮或将鼠标悬停在按钮上时更改 MC 的 X 值。 我已经设法做到了这一点,但它仅移动了我在鼠标事件后输入的一个值。 这是我做的一段代码。

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonL1Pressed);


function buttonL1Pressed(event:MouseEvent):void{

var temp:int = 0;
var temp1:int = 0;
temp = paleta1_mc.x;
temp1 = temp - 5;
paleta1_mc.x = temp1;
trace(temp1);


}

我希望你能理解我,并知道如何帮助我解决这个问题。

预先非常感谢您!

干杯, 伊万

I'm new here, just found these forums on Google.

First of all, I want to appologise if there is some topics like this, but I searched whole forums and didn't find any that finishes my problem.

Now the important one. As I stated in topic title, I need an AS3 code that's doing the thing. This is what I want to
accomplish. I have a MC(image) in the center of my screen, and have two buttons, one on right and one on left
side of that MC. I want to scroll (image is like a menu) that MC left or right on mouse events, down or over.
So, I just want to change MCs X value while holding mouse button on buttons or just hovering over them.
I have managed to do that, but it's only moving by one value I have entered after a mouse event.
Here's a piece of code I did.

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonL1Pressed);


function buttonL1Pressed(event:MouseEvent):void{

var temp:int = 0;
var temp1:int = 0;
temp = paleta1_mc.x;
temp1 = temp - 5;
paleta1_mc.x = temp1;
trace(temp1);


}

I hope you understood me, and have a clue how to help me with this.

Thank you very much in advance!

Cheers,
Ivan

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

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

发布评论

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

评论(2

渡你暖光 2024-09-06 15:03:34

试试这个:

var isScrolling = false;

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, function(e){isScrolling =true});
buttonL1_btn.addEventListener(MouseEvent.MOUSE_OUT, function(e){isScrolling =false});
this.addEventListener(Event.ENTER_FRAME,checkAction)

function checkAction(event:Event):void{

  if (isScrolling)
  {
     paleta1_mc.x -=5;
  }

}

Try this:

var isScrolling = false;

buttonL1_btn.addEventListener(MouseEvent.MOUSE_OVER, function(e){isScrolling =true});
buttonL1_btn.addEventListener(MouseEvent.MOUSE_OUT, function(e){isScrolling =false});
this.addEventListener(Event.ENTER_FRAME,checkAction)

function checkAction(event:Event):void{

  if (isScrolling)
  {
     paleta1_mc.x -=5;
  }

}
ぺ禁宫浮华殁 2024-09-06 15:03:34

您似乎将事件侦听器附加到 MOUSE_OVER 事件而不是 MOUSE_DOWN ?由于您的处理函数名为 buttonL1Pressed,我假设您希望在用户单击按钮时而不是在鼠标光标位于按钮上时触发该事件。

抱歉,我不太清楚你在问什么,但是当我阅读你的代码时,我突然意识到了这一点。

如果您能提供更多详细信息,我很乐意提供帮助。

It looks like you're attaching the event listener to the MOUSE_OVER event instead of MOUSE_DOWN? Since your handler function is called buttonL1Pressed, I assume you want the event to fire when the user clicks the button instead of when the mouse cursor is over it.

Sorry, I'm not entirely clear what you're asking, but that jumped out at me as I was reading your code.

If you can provide a little more detail, I'd be happy to help if I can.

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