PDA

View Full Version : AS3: Smoothing with Loader



rooterman42
December 17th, 2009, 12:46 PM
Hello,

I'm trying to apply smoothing to my images on loading, but my smoothing code keeps throwing this error:

[object Loader]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at gallery_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()


Here's the code, please let me know what I'm doing wrong, and thanks in advance:


//......XML LOADER........

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("../swf/xml/gallery.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);

//......OTHER VARIABLES.......

var xmlList:XMLList;
var dataLoader:Loader;

//........PROCESS XML FUNCTION.......

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

//.......LOOP XML FOR IMAGES...........

for(var i:int =1; i < xmlList.length(); i++)
{
dataLoader = new Loader();
dataLoader.load(new URLRequest(xmlList[i].image));
trace (dataLoader);

var smoothImage:Bitmap = Bitmap(dataLoader.content);
smoothImage.smoothing=true;

gallery_mc["panel"+i]["image"+i].addChild(smoothImage);
}// closes loop
} // closes process xml

//----xml end----

Aurelien
December 18th, 2009, 08:12 AM
Your code doesn't work because you are trying to access the content of the Loaders before they have actually loaded anything.

You have to wait until the loading is complete to access of the property of the content object. For instance :



// inside your loop :
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadingComplete, false, 0, true );
loader.load( new URLRequest( xmlList[ i ].image ) );

// function handling the COMPLETE Event :
function loadingComplete( e:Event ):void {
var bitmapContent:Bitmap = Bitmap( e.target.content );
bitmapContent.smoothing = true;
addChild( bitmapContent );
}