actionscript 3 - How to programmatically drag and drop a Sprite in Flex? -


I need some action code to simulate the drag and drop of the spread, I was thinking that it is possible to do this is? if so?

For example, to simulate a click on Sprite, I can get from the following line of code.

  sprite.dispatchEvent (click on the new MouseEvent (MouseEvent.));  

Do something like this:

  mySprite .addEventListener ("MouseDown", MouseDownHandler); Forum. AddEventListener ("mouseup", mouse mount handler); Protected function mouseDownHandler (e: MouseEvent): zero {e.target.startDrag (); } Secure function mouseDownHandler (e: MouseEvent): zero {e.target.stopDrag (); }  

You can pass 2 arguments to the startDrag method, first there is a boolean to lock in the center, the second is a rectangular object for the boundary number.

For more controlled behavior, you can do something like this instead:

  mySprite.addEventListener ("mousedown", mouse downhandler); Forum. AddEventListener ("mouseup", mouse mount handler); Protected function mouseDownHandler (e: MouseEvent): zero {stage.addEventListener ("mouseMove", mouseMoveHandler); } Secure function mouseDownHandler (e: MouseEvent): zero {stage.removeEventListener ("mouseMove", mouseSoffHandler); } Safe Function Mousehandhandler (E: MouseEvent): Zero {mySprite.x = mouseX; MySprite.y = Katar; }  

(code is not tested, so some minor syntax-errors or something may be)


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -