AS3 Bitmap Smoothing in Flash tagged:

AS3 Bitmap Smoothing in Flash

Posted by admin in ActionScript 3, Flash, Tutorials

This is just a small experiment on Flash bitmap smoothing in ActionScript 3. A small piece of codes can be sometimes too hard if one does not know how to write it properly. You may try the below sample and adapt it for your own Flash projects.

View Sample SWF File or Download Flash Source File (Adobe Flash CS3 is required to open it)

Actionscript:
  1. var flashmo_bm:Bitmap = new Bitmap();
  2. var flashmo_mc:MovieClip = new MovieClip();
  3. var pic_request:URLRequest = new URLRequest(“flashmo_400×300_02.jpg”);
  4. var pic_loader:Loader = new Loader();pic_loader.load(pic_request);
  5. pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loaded);
  6. pic_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, on_progress);
  7. flashmo_info.text = “”;function on_loaded(e:Event):void
  8. {
  9. flashmo_bm = Bitmap(pic_loader.content);
  10. flashmo_bm.x = – flashmo_bm.width * 0.5;
  11. flashmo_bm.y = – flashmo_bm.height * 0.5;
  12. flashmo_bm.smoothing = true;
  13.  
  14. flashmo_mc.addChild(flashmo_bm);
  15. flashmo_mc.x = stage.stageWidth * 0.5;
  16. flashmo_mc.y = stage.stageHeight * 0.5;
  17. flashmo_mc.buttonMode = true;
  18. stage.addChild(flashmo_mc);
  19.  
  20. flashmo_info.text = “Bitmap smoothing is “ + flashmo_bm.smoothing;
  21. flashmo_mc.addEventListener( MouseEvent.MOUSE_DOWN, activate );
  22. flashmo_mc.addEventListener( MouseEvent.CLICK, deactivate );
  23. toggle_button.addEventListener( MouseEvent.CLICK, toggle_smoothing );
  24. }
  25. function on_progress(e :P rogressEvent):void
  26. {
  27. var percent:Number = Math.round(e.bytesLoaded / e.bytesTotal * 100);
  28. flashmo_info.text = “Loading… “ + percent + “%”;
  29. }
  30. function activate(e:MouseEvent):void
  31. {
  32. this.addEventListener( Event.ENTER_FRAME, moving );
  33. }
  34. function deactivate(e:MouseEvent):void
  35. {
  36. this.removeEventListener( Event.ENTER_FRAME, moving );
  37. }
  38. function moving(e:Event):void
  39. {
  40. flashmo_mc.rotation = mouseX + stage.stageWidth;
  41. flashmo_mc.x = mouseX;
  42. flashmo_mc.y = mouseY;
  43. flashmo_mc.scaleX = flashmo_mc.scaleY = 0.003 * mouseY + 0.2;
  44. }
  45. function toggle_smoothing(e:MouseEvent):void
  46. {
  47. if( flashmo_bm.smoothing == true )
  48. flashmo_bm.smoothing = false;
  49. else
  50. flashmo_bm.smoothing = true;
  51. flashmo_info.text = “Bitmap smoothing is “ + flashmo_bm.smoothing;
  52. }