PDA

View Full Version : Smooth bitmap problem



bartvdb
March 4th, 2007, 04:50 PM
Hey Guys,

I love this forum.
I've found a lot of helpful tips here, but this time I'm having a bit of a problem.

I'm using this code to load a different, fullscreen background in to my site every time it loads:



stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;
//StageAlign
Stage.scaleMode = "noScale";
Stage.align = "LT";
bg._alpha = 0;
_root.mc_preloader.bar._visible = false;
_root.mc_preloader.pText._visible = false;
//AspectRatio & Fullscreen achtergrond
Stage.addListener(bg);
bg.onResize = function() {
var imageAspectRatio = this.bgLoad._width/this.bgLoad._height;
var stageAspectRatio = Stage.width/Stage.height;
if (stageAspectRatio>=imageAspectRatio) {
this._width = Stage.width;
this._height = Stage.width/imageAspectRatio;
} else {
this._height = Stage.height;
this._width = Stage.height*imageAspectRatio;
}
this._x = -(this._width-Stage.width)/2;
this._y = -(this._height-Stage.height)/2;
};
//MclListener
var mclListener:Object = new Object();
mclListener.onLoadProgress = function(mc, w, t) {
_root.mc_preloader.bar._visible = true;
_root.mc_preloader.pText._visible = true;
_root.mc_preloader.bar._width = (w/t)*100;
_root.mc_preloader.pText = Math.round((w/t)*100)+"%";
var w = image_mc.getBytesLoaded();
var t = image_mc.getBytesTotal();
};
mclListener.onLoadInit = function(mc:MovieClip) {
_root.bg.onResize();
};
mclListener.onLoadComplete = function(mc:MovieClip) {
var bgAlpha:Tween = new Tween(bg, "_alpha", Strong.easeOut, 0, 100, 1, true);
var prcAlpha:Tween = new Tween(mc_preloader, "_alpha", Strong.easeOut, 100, 0, 2, true);
bgAlpha.onMotionFinished = function() {
_root.gotoAndPlay(2);
};
};
var image_mc1:MovieClipLoader = new MovieClipLoader();
image_mc1.addListener(mclListener);
// Achtergrond laden via xml
var bg_xml = new XML();
bg_xml.ignoreWhite = true;
bg_xml.load("backgrounds.xml");
bg_xml.onLoad = function(success) {
counter = bg_xml.firstChild.childNodes.length;
i = Math.floor(Math.random()*counter);
image_mc1.loadClip(this.firstChild.childNodes[i].childNodes[0].attributes.url, bg.bgLoad);
};


But when the screen resizes, the image becomes unsmooth.
I'd like to get my backgrounds smoothed, but I don"t know how to do this with as. I've tried out loadBitmapSmoothed() (http://proto.layer51.com/d.aspx?f=1442) , but I can't get this to work.

Anyone who can help me with this? I'd be forever grateful.

Thanks,

Bartvdb

bartvdb
March 5th, 2007, 10:31 AM
*Bump*

Anyone? Thanks in advance!

dfm
March 5th, 2007, 11:05 PM
I would like that kind of help too...


Thanks for all

Dfm

bartvdb
March 7th, 2007, 10:28 AM
I've found this thread (http://www.kirupa.com/forum/showthread.php?p=2078696#post2078696)and solved the problem:

This is the code:


Stage.scaleMode ="noScale";
Stage.align = "LT";

import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.display.*;

function loadBitmapSmoothed(url:String, target:MovieClip) {

var bmc:MovieClip = target.createEmptyMovieClip(
"bmc",
target.getNextHighestDepth()
);

var listener:Object = new Object();
listener.tmc = target;

listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
percent = Math.round((bytesLoaded/bytesTotal)*100);
pText.text = percent+"%";
}

listener.onLoadInit = function(mc:MovieClip) {
mc._visible = false;

var bitmap:BitmapData = new BitmapData(
mc._width,
mc._height,
true
);

this.tmc.attachBitmap(
bitmap,
this.tmc.getNextHighestDepth(),
"auto",
true
);
bitmap.draw(mc);

// set size and position on load
if(Stage.height/Stage.width > target._height/target._width) {
img_prop = target._width/target._height;
target._height = Stage.height;
target._width = Stage.height*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
} else {
img_prop = target._height/target._width;
target._width = Stage.width;
target._height = Stage.width*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
}
};

var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}



var bg_xml = new XML();
bg_xml.ignoreWhite = true;
bg_xml.load("../_achtergronden/achtergronden_og.xml");
bg_xml.onLoad = function(success) {
counter = bg_xml.firstChild.childNodes.length;
i = Math.floor(Math.random()*counter);
loadBitmapSmoothed(this.firstChild.childNodes[i].childNodes[0].attributes.url, bg_con);

var bgAlpha:Tween = new Tween(bg_con, "_alpha", Strong.easeOut, 0, 100, 1, true);
bgAlpha.onMotionFinished = function() {
_root.gotoAndPlay(2);
};
};


// set size and position on resize
var stage_listener:Object = new Object();
stage_listener.onResize = function():Void {
if(Stage.height/Stage.width > bg_con._height/bg_con._width) {
img_prop = bg_con._width/bg_con._height;
bg_con._height = Stage.height;
bg_con._width = Stage.height*img_prop;
bg_con._y = (Stage.height/2)-(bg_con._height/2);
bg_con._x = (Stage.width/2)-(bg_con._width/2);
} else {
img_prop = bg_con._height/bg_con._width;
bg_con._width = Stage.width;
bg_con._height = Stage.width*img_prop;
bg_con._y = (Stage.height/2)-(bg_con._height/2);
bg_con._x = (Stage.width/2)-(bg_con._width/2);
}
}

Stage.addListener(stage_listener);