简体   繁体   English

按住鼠标按钮时,为什么SimpleButtons停止检测超载状态?

[英]When the mouse button is held down, why do SimpleButtons stop detecting over state?

I was hoping to gain some insight as to why Flash acts in a particular way. 我希望对Flash为什么以特定方式起作用有所了解。 Here is the scenario: if you... 这是场景:如果您...

1) add a SimpleButton to the stage and view the SWF 1)在舞台上添加一个SimpleButton并查看SWF
2) then press and hold the mouse button down OUTSIDE of the button's boundaries 2)然后在按钮边界外按住鼠标按钮
3) then drag the cursor over the SimpleButton while still holding down the mouse button... 3)然后将光标拖到SimpleButton上,同时仍然按住鼠标按钮...

...Then the SimpleButton on the stage does not detect the mouseover and display its 'over' state. ...然后,舞台上的SimpleButton不会检测到鼠标悬停并显示其“悬停”状态。 It just stays in its idle state. 它只是保持其空闲状态。 Why is this? 为什么是这样? And is there a way to enable the SimpleButton to display its over state while the mouse button is being held down and then the cursor brought on top of the button (as described above)? 是否有一种方法可以使SimpleButton在按住鼠标按钮然后将光标移到按钮顶部时显示其结束状态(如上所述)?

That's the abstract, and if you are at all curious (this won't elaborate on the question, but maybe help you visualize a practical scenario) what's motivating the question, it is an application I'm building. 那是抽象的,如果您完全好奇(这不会详细说明问题,但也许可以帮助您直观地看到实际情况),那么促使问题产生的是我正在构建的应用程序。 In this app, the user is able to drag video thumbnails in order to rearrange their order. 在此应用中,用户可以拖动视频缩略图以重新排列顺序。 When a user begins dragging a video clip, a visual indicator is activated so the user knows where the clip will be placed when the user releases the mouse button (eg the clip was in position 1, and the user drags it between clips 4 and 5. A visual indicator--a SimpleButton--would, ideally, show the user that it will be dropped between clips 4 and 5 if the user releases the mouse button). 当用户开始拖动视频剪辑时,视觉指示器会被激活,因此当用户释放鼠标按钮时(例如,剪辑位于位置1,并且用户将其拖动到剪辑4和5之间),用户便知道该剪辑将放置在哪里。理想情况下,可视指示器(SimpleButton)将向用户显示,如果用户释放鼠标按钮,它将被放置在剪辑4和5之间。

Thanks for the insight! 感谢您的见解!

Actually, the MOUSE_OVER event fires just fine (just add an event listener with a simple trace - it's there!), no matter where the mousebutton was clicked - the SimpleButton just doesn't change visible state. 实际上,无论单击鼠标按钮的位置在哪里,MOUSE_OVER事件都可以正常触发(只需添加带有简单跟踪的事件侦听器即可!),无论单击鼠标按钮的位置在哪里,SimpleButton都不会更改可见状态。

If you want your Button to behave differently, you will have to create listener functions and change the state manually. 如果希望Button的行为不同,则必须创建侦听器功能并手动更改状态。 You can extend the SimpleButton class and add set downState, upState and overState to visible = true; 您可以扩展SimpleButton类,并将set downState,upState和overState添加到visible = true; ;。 or visible = false; visible = false; in whichever combination suits your desired behavior best. 哪种组合最适合您所需的行为。

it's possible to create a MOUSE_MOVE event handler and check if cursor coordinates are inside of the button bounds (and if they are - toggle 'over' state). 可以创建一个MOUSE_MOVE事件处理程序,并检查光标坐标是否在按钮范围内(如果它们是-切换“悬停”状态)。
also a MOUSE_MOVE listener in the button instance might detect mouse over it even while it's pressed 按钮实例中的MOUSE_MOVE侦听器也可能会检测到鼠标悬停

A simple hitTest between your dragged icon and the visual indicator would work just fine for that kind of thing. 在拖动的图标和可视指示器之间进行简单的hitTest可以很好地处理这种情况。

You could have something like this: 您可能会有这样的事情:

function myHitTest(e:Event):void {
    if (myButton.hitTestObject(myVisualIndicator)) {
        myVisualIndicator.visible=true;
    } else {
       myVisualIndicator.visible=false;
    }
 }

On mouse down you could set an enterframe event listener for that function and clear it on mouse release. 按下鼠标时,您可以为该功能设置Enterframe事件监听器,并在释放鼠标时将其清除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM