Ultrashock Forums > Flash > ActionScript
• the right way to allow smoothing for loaded .jpg's

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
the right way to allow smoothing for loaded .jpg's
Old 2009-06-25

hi all.


I'm in the middle on a problem and I need help.
I'm loading an external .jpg and moving it across stage.

if I was to do this with a .jpg already in the Library, the movement would look much better if I manually activated "allow smoothing" from the .jpg's properties.

so I'm trying to do the same for the loaded picture.
what I've done so far is loading the picture, wait until it's completely loaded and then convert the content of the loader to bitmap and setting the smoothing property of this bitmap to true.

...OR, this is what I'm trying to do.
here's my code:

Code:
var _loader:Loader;
var _loaderArray:Array = [];
var _picture:String = "billeder/h1.jpg";

loadPicture(_picture);

function loadPicture(s:String) {
	
	var picture:String = s;
	
	_loader = new Loader();
	_loader.alpha = 1;
	_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showLoading);
	_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doneLoading);
	_loader.load(new URLRequest(picture));

}

function showLoading(e:Event):void {
	trace("preloading");
}

function doneLoading(e:Event):void {
	
	var bit:Bitmap = e.target.content
	if(bit != null){
		bit.smoothing = true;
	}
	
	addChild(_loader);
	
	trace("e.target.content = "+e.target.content);

	_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, showLoading);
	_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, doneLoading);

}
am I doing this correctly?


thanks
felisan
---------------------------------------------
http://www.campjohn.dk/wp/
postbit arrow 4 comments | 195 views postbit arrow Reply: with Quote   
Registered User
felisan is offline
seperator
Posts: 234
2005-02-18
Age: 33
felisan lives in Denmark
seperator

Ultrashock Member Comments:
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2009-06-25 #2 Old  
Hey Felisian

try this


Code:
function doneLoading(e:Event):void 
{
	var bit:Bitmap = e.target.content as Bitmap;
        bit.smoothing = true;
        
        _loader.addChild( bit );
	addChild(_loader);

	_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, showLoading);
	_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, doneLoading);

}
Reply With Quote  
felisan felisan is offline felisan lives in Denmark 2009-06-25 #3 Old  
hi Laveklint.


sorry, that's no good, gives me this error:
Error: Error #2069: The Loader class does not implement this method.
at Error$/throwError()
at flash.display::Loader/addChild()
at ArrayStuff/doneLoading()



thanks
felisan
Reply With Quote  
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2009-06-25 #4 Old  
sorry about that.. donīt know what I was thinking about.

try this instead:

Code:
// create a new sprite that will hold the loaded image
var _imageContainer:Sprite = new Sprite();
var _loader:Loader;
var _loaderArray:Array = [];
var _picture:String = "billeder/h1.jpg";

loadPicture(_picture);

function loadPicture(s:String) {
	
	var picture:String = s;
	
	_loader = new Loader();
	_loader.alpha = 1;
	_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showLoading);
	_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, doneLoading);
	_loader.load(new URLRequest(picture));

}

function showLoading(e:Event):void {
	trace("preloading");
}

function doneLoading(e:Event):void {
	
	var bit:Bitmap = e.target.content as Bitmap;
        bit.smoothing = true;

	// this line will add the loaded content to the _imageContainer-sprite
	_imageContainer.addChild( bit );

	_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, showLoading);
	_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, doneLoading);

}
Reply With Quote  
felisan felisan is offline felisan lives in Denmark 2009-07-04 #5 Old  
thanks!

anyway, project ended, and I have summed a bit up here:
http://www.campjohn.dk/wp/?p=996

I'm not sure how useful it really is, but I know that I in the future will try to combine moving pictures like that with the "Ken Burns" effect to hopefully make it smoother.



kind regards
felisan
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: