Scale and rotate the visualization objects in flex on a multi-touch screen

Source: Internet
Author: User
One of my friends once said that scaling and rotating an image on a multi-touch screen should be as basic as "Hello World" in the program. I think this is very reasonable. In the first part of the video (two parts in total), I will explain how to make the flex component rotate and zoom. The following class allows the image to be scaled and rotated, which is as classic as "Hello World" and also applies to videos and containers. This greatly enhances the user experience.


The following is the content of the class, which can be applied in most programs.

Rotatablescalable:

  1. Package com. mlegrand
  2. {
  3. Import flash. display. displayobject;
  4. Import flash. Events. transformgestureevent;
  5. Import flash. Geom. matrix;
  6. Import flash. Geom. Point;
  7. Import flash. UI. multitouch;
  8. Import flash. UI. multitouchinputmode;

  9. Public class rotatablescalable
  10. {

  11. Protected var diso: displayobject

  12. Public Function rotatablescalable (displayobject: displayobject)
  13. {
  14. Diso = displayobject;
  15. If (multitouch. supportsgestureevents)
  16. {
  17. Multitouch. inputmode = multitouchinputmode. gesture;
  18. Addgestureeventlisteners ()
  19. }

  20. }

  21. Protected function addgestureeventlisteners (): void
  22. {
  23. Diso. addeventlistener (transformgestureevent. gesture_rotate, gesturerotatehandler );
  24. Diso. addeventlistener (transformgestureevent. gesture_zoom, gesturezoomhandler );
  25. }

  26. Protected function gesturerotatehandler (Event: transformgestureevent): void
  27. {
  28. Event. stopimmediatepropagation ();
  29. VaR M: matrix = diso. Transform. matrix;
  30. VaR P: Point = M. transformpoint (new point (diso. width/2, diso. Height/2 ));
  31. M. Translate (-p. x,-P. y );
  32. M. Rotate (event. Rotation * (math. PI/180 ));
  33. M. Translate (P. X, p. y );
  34. Diso. Transform. Matrix = m;
  35. }

  36. Protected function gesturezoomhandler (Event: transformgestureevent): void
  37. {
  38. Event. stopimmediatepropagation ();
  39. VaR M: matrix = diso. Transform. matrix;
  40. VaR P: Point = M. transformpoint (new point (diso. width/2, diso. Height/2 ));
  41. M. Translate (-p. x,-P. y );
  42. M. Scale (event. scalex, event. scaley );
  43. M. Translate (P. X, p. y );
  44. Diso. Transform. Matrix = m;
  45. }

  46. }
  47. }

Copy code

Note: I have read some matrix changes on Justin Imhoff's blog. I strongly recommend that you subscribe to his blog through feed. I also noted that natural
User Interface Group. This forum is very good. We recommend that you check out the friends and sisters who are interested in multi-touch.

Reprinted: http://bbs.9ria.com/thread-44732-1-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.