Multimedia interaction application BASICS (9)

Source: Internet
Author: User

 

Q: How can I scale an externally loaded image?

 

Step 1: Load External images. Second, use its scalex and scaley attributes to scale their proportions, and third, scale proportionally by clicking an event.

  1. Package
  2. {
  3. Import flash. display. movieclip;
  4. Import flash. Events .*;
  5. Import flash. display. loader;
  6. Import flash.net. URLRequest;
  7. Import flash. display. Bitmap;
  8. Public class example extends movieclip
  9. {
  10. Public Function example ()
  11. {
  12. Init ();
  13. }
  14. Private function Init (): void
  15. {
  16. VaR _ Loader: loader = new loader ();
  17. _ Loader. Load (New URLRequest ("1.jpg "));
  18. _ Loader. contentloaderinfo. addeventlistener (event. Complete, loadhander );
  19. _ Loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, iohander );
  20. }
  21. Private function loadhander (E: Event): void
  22. {
  23. Trace ("loaded successfully ");
  24. Trace(e.tar get. content );
  25. VaR image: bitmap = E. currenttarget. content as bitmap;
  26. // Var bitmap: bitmapdata = image. bitmapdata;
  27. VaR MC: movieclip = new movieclip ();
  28. MC. addchild (image );
  29. Addchild (MC );
  30. MC. scalex = 0.2; // set the percentage after loading to 0.2.
  31. MC. scaley = 0.2; // set the proportion of the uploaded image to 0.2.
  32. MC. Rotation =-30; // convert its angle to-30 degrees.
  33. MC. x = stage. stagewidth/2-100; // set the X coordinate
  34. MC. Y = stage. stageheight/2-100; // set Y coordinates
  35. MC. addeventlistener (mouseevent. Click, onclick );
  36. }
  37. Private function iohander (E: ioerrorevent): void
  38. {
  39. Trace ("loading error ");
  40. }
  41. Private function onclick (E: mouseevent): void
  42. {
  43. Trace ("You clicked on me ");
  44. E. currenttarget. scalex = 1; // restore the original proportion
  45. E. currenttarget. scaley = 1;
  46. }
  47. }
  48. }

Add a proportional scaling code based on the Code of multimedia application base 8. Such an image can be scaled, but the effect is not monotonous, not dynamic. To achieve its dynamic effect, we add a buffer to make the interaction more exciting.

 

Output result:

 

 

Question 2: How to buffer images?

 

Step 1: Use the buffer function to import two packages

Import Fl. transitions. Tween;
Import Fl. transitions. Easing .*;

 

Official Document reference:

The tween class allows you to move, resize, and fade in and out a video clip by specifying the attributes of the target video clip to play an animated effect in several frames or seconds.

 

The tween class also allows you to specify various easing methods. "Easing" is the progressive acceleration and progressive deceleration effect during the animation operation, which helps make the animation more realistic. The fl. transitions. Easing package provides many easing methods (including the equations for acceleration and deceleration) that change the easing animation accordingly.

 

The fl. transitions. Easing package contains classes that can be used with the fl. transitions class to create easing effects. "Easing" refers to the gradual acceleration or deceleration in the animation process, which will make your animation look more realistic. The classes in this package support multiple easing effects to enhance the animation effect.

  1. Package
  2. {
  3. Import flash. display. movieclip;
  4. Import flash. Events .*;
  5. Import flash. display. loader;
  6. Import flash.net. URLRequest;
  7. Import flash. display. Bitmap;
  8. Import Fl. transitions. Tween;
  9. Import Fl. transitions. Easing .*;
  10. Public class example extends movieclip
  11. {
  12. Private var key: Boolean = true;
  13. Public Function example ()
  14. {
  15. Init ();
  16. }
  17. Private function Init (): void
  18. {
  19. VaR _ Loader: loader = new loader ();
  20. _ Loader. Load (New URLRequest ("1.jpg "));
  21. _ Loader. contentloaderinfo. addeventlistener (event. Complete, loadhander );
  22. _ Loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, iohander );
  23. }
  24. Private function loadhander (E: Event): void
  25. {
  26. Trace ("loaded successfully ");
  27. Trace(e.tar get. content );
  28. VaR image: bitmap = E. currenttarget. content as bitmap;
  29. // Var bitmap: bitmapdata = image. bitmapdata;
  30. VaR MC: movieclip = new movieclip ();
  31. MC. addchild (image );
  32. Addchild (MC );
  33. MC. scalex = 0.2;
  34. MC. Scaling = 0.2;
  35. MC. Rotation =-30;
  36. MC. x = stage. stagewidth/2-100;
  37. MC. Y = stage. stageheight/2-100;
  38. MC. addeventlistener (mouseevent. Click, onclick );
  39. }
  40. Private function iohander (E: ioerrorevent): void
  41. {
  42. Trace ("loading error ");
  43. }
  44. Private function onclick (E: mouseevent): void
  45. {
  46. Trace ("You clicked on me ");
  47. If (key)
  48. {
  49. VaR mytween: tween = new tween (E. currenttarget, "scalex", elastic. easeout, 0.2, 1, 3, true );
  50. VaR mytween2: tween = new tween (E. currenttarget, "scaley", elastic. easeout, 0.2, 1, 3, true );
  51. Key = false;
  52. } Else
  53. {
  54. VaR mytween3: tween = new tween (E. currenttarget, "scalex", elastic. easeout, 1, 0.2, 3, true );
  55. VaR mytween4: tween = new tween (E. currenttarget, "scaley", elastic. easeout, 1, 0.2, 3, true );
  56. Key = true;
  57. }
  58. }
  59. }
  60. }

The tween class is used to achieve the image buffering effect. After you set the initial scaling ratio to 0.2 clicks, the ratio can be restored to achieve some effect.

You can also modify elastic. easeout to make it more effective. In this way, we can use it to achieve the effect.

Output result:

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.