Loader, Centering, Smoothing

Actionscript:
  1. var image:Loader = new Loader();
  2. image.load(new URLRequest("http://www.shapevent.com/sketchbook/wp-content/uploads/avalanche.jpg"));
  3. image.x = stage.stageWidth / 2;
  4. image.y = stage.stageHeight / 2;
  5. addChild(image);
  6.  
  7. image.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
  8. function onComplete(evt:Event):void {
  9.    
  10.     // CENTER THE IMAGE
  11.     image.content.x = -image.content.width / 2;
  12.     image.content.y = -image.content.height / 2;
  13.    
  14.     // BITMAP SMOOTHING
  15.     Bitmap(image.content).smoothing = true;
  16.     image.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
  17. }
  18.  
  19.  
  20. // scale the image with the mouse to demonstrate smoothing and scaling from the center
  21. addEventListener(Event.ENTER_FRAME, onLoop);
  22. function onLoop(evt:Event):void {
  23.     image.scaleX = image.scaleY = mouseX / stage.stageWidth;
  24. }

This is really two snippets combined. How to scale the content of a Loader from the center:

Actionscript:
  1. // CENTER THE IMAGE
  2. image.content.x = -image.content.width / 2;
  3. image.content.y = -image.content.height / 2;

and how to smooth a jpg, png etc... that has been loaded dynamically into your swf:

Actionscript:
  1. // BITMAP SMOOTHING
  2. Bitmap(image.content).smoothing = true;

This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Bunyana
    Posted May 24, 2010 at 7:53 am | Permalink

    Thank you for the articel…very good for learn…

  2. me
    Posted January 2, 2011 at 10:30 am | Permalink

    thanks mate..,
    really got that smoothing thingy..,
    hahaha..,

  3. Hendrik
    Posted September 14, 2011 at 7:00 am | Permalink

    Hey,
    nice Post, only 1 suggestions:
    If you are using the Bitmap smooth function in some cases you will get security errors, so you have to add:
    var loadCon: LoaderContext = new LoaderContext(true);
    and load by
    image.load(requ , loadCon);
    to check the policy files ;)

    … but anyway thanks for the Bitmapsmooth hint… i was not aware you can aply this inside a loader…

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*