开发者

Mouse coordinates action

Is there a way to do it in Flex to say:

if mouseClick x<300&y&开发者_运维百科lt;200 currentState='';

Thanks,


Many objects dispatch a click event; and in that click event properties you can access the x and y position using stageX and stageY properties.

http://livedocs.adobe.com/flex/3/langref/flash/events/MouseEvent.html

However, I do not think it is possible to listen for a click event at a specific location without their being a UI Element at that spot.

I also question whether hard coding the x and y position for such a state change is a good idea; as different machines and different screen sizes and resolutions may size your content differently.


You can add a listener to the stage to capture all clicks:

package
{

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

[SWF(width='500', height='300', backgroundColor='#ffffff', frameRate='30')]
public class ClickTest extends Sprite
{
    public function ClickTest()
    {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
    }

    private function addedToStage(event:Event):void
    {
        stage.addEventListener(MouseEvent.CLICK, handleClick);
    }

    private function handleClick(event:MouseEvent):void
    {
        if((stage.mouseX < 300) && (stage.mouseY < 200)
        {
            trace("CLICKED WHERE I WANT");
        }
    }
}

}

This seems to work even when Sprites are placed on top of the interface.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜