Log in

View Full Version : Cannot get image smoothing to work with my AS3 script



BioFUSION
07-09-2010, 10:04 PM
Hey guys, been trying different tutorials but not getting
anywhere here.

Below is my actionscript, UILoader loads an external image
from an XML file and shrinks it down to fit into the 205x205
box. But it makes the images look funky and distorted.

Can anyone tell me what I am doing wrong here. I am a
beginner to AS3, got this to work via a few found tuts
scattered around online.


var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("previews.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

import fl.containers.UILoader;


function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();

var aLoader:UILoader = new UILoader();
aLoader.load(new URLRequest(xmlList[0].attribute("image")));
aLoader.width = 205;
aLoader.height = 205;
aLoader.x = 0;
aLoader.y = 0;


var link:URLRequest = new URLRequest("home.html");

aLoader.buttonMode = true;
aLoader.addEventListener(MouseEvent.CLICK, gooo);

function gooo(event:MouseEvent):void {
navigateToURL(link, '_self');
}

var border:DropShadowFilter = new DropShadowFilter();
border.blurX = 0;
border.blurY = 0;
border.distance = 0;
border.strength = 0;
border.inner = true;
border.color = 0xFFFFFF;
border.alpha = 1;

aLoader.filters = [border];
addChild(aLoader);

}

BioFUSION
07-10-2010, 06:59 PM
Wow, I figured it was something simple, but if 50 something people don't know then I don't feel so bad.

djr33
07-10-2010, 09:12 PM
To be honest, few users here are experts with flash. A few know it very well, but perhaps have never had this problem. Also, many of the "views" for the thread may be search engine bots, not users.
You may get a better answer for this at a flash-only forum, while you'll usually get a good answer here for questions about Javascript/HTML/CSS/PHP/etc.

BioFUSION
07-10-2010, 09:44 PM
Well appreciate you letting me know. I'll try another forum.

auntnini
07-10-2010, 09:59 PM
Have not had time to digest that complicated script. Suspect the distortion has sosmething to do with the image aspect ratio.

This from Adobe for Flash CS3:


http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000480.html
The UILoader component is a container that can display SWF, JPEG, progressive JPEG, PNG, and GIF files. You can use a UILoader whenever you need to retrieve content from a remote location and pull it into a Flash application. For example, you could use a UILoader to add a company logo (JPEG file) to a form. You could also use the UILoader component in an application that displays photos. Use the load() method to load content, the percentLoaded property to determine how much content has loaded, and the complete event to determine when loading is finished. You can scale the contents of the UILoader or resize the UILoader itself to accommodate the size of the contents. By default, the contents are scaled to fit the UILoader. You can also load content at run time and monitor loading progress (although after content has been loaded once it is cached, the progress jumps to 100% quickly). If you specify a location when loading content in the UILoader, you must specify the location (X and Y coordinates) as 0, 0.

BenDeJo
11-08-2010, 10:56 PM
Found this AS
http://bknr.net/svn/trunk/thirdparty/yui/as-src/charts/com/yahoo/yui/charts/BackgroundAndBorder.as

Making the "example":


var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("previews.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

import fl.containers.UILoader;


function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();

var aLoader:UILoader = new UILoader();
aLoader.load(new URLRequest(xmlList[0].attribute("image")));
// new line of code
aLoader.addEventListener(Event.COMPLETE, onComplete);
//
aLoader.width = 205;
aLoader.height = 205;
aLoader.x = 0;
aLoader.y = 0;


var link:URLRequest = new URLRequest("home.html");

aLoader.buttonMode = true;
aLoader.addEventListener(MouseEvent.CLICK, gooo);

function gooo(event:MouseEvent):void {
navigateToURL(link, '_self');
}

var border:DropShadowFilter = new DropShadowFilter();
border.blurX = 0;
border.blurY = 0;
border.distance = 0;
border.strength = 0;
border.inner = true;
border.color = 0xFFFFFF;
border.alpha = 1;

aLoader.filters = [border];
addChild(aLoader);

}

//new function
function onComplete(e:Event):void
{
trace("onComplete " + e);
trace("e.currentTarget.content "+e.currentTarget.content);
if(e.currentTarget.content is Bitmap)
{
Bitmap(e.currentTarget.content).smoothing = true;
}
}

I Hope this helps. It works for me.