开发者

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. Here is the scenario: if you...

1) add a SimpleBut开发者_如何学运维ton to the stage and view the SWF

2) then press and hold the mouse button down OUTSIDE of the button's boundaries

3) then drag the cursor over the SimpleButton while still holding down the mouse button...

...Then the SimpleButton on the stage does not detect the mouseover and display its 'over' state. 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)?

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 (e.g. 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).

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.

If you want your Button to behave differently, you will have to create listener functions and change the state manually. You can extend the SimpleButton class and add set downState, upState and overState to visible = true; or 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).
also a MOUSE_MOVE listener in the button instance might detect mouse over it even while it's pressed


A simple hitTest between your dragged icon and the visual indicator would work just fine for that kind of thing.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜