1 Replies - 2137 Views - Last Post: 30 September 2012 - 04:54 AM

#1 1st Paradox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-September 12

Problem loading XML images in OOP

Posted 30 September 2012 - 03:16 AM

Hi, I'm having a little trouble trying to load images from an XML file into a class. This is the first time I have attempted OOP but have some experience with Procedural AS3. I think it is just an issue with the difference in naming in OOP in comparison with Procedural but I cant figure it out.

Here is the XML I have created, nice and simple.
<?xml version="1.0" encoding="utf-8"?>
<GALLERY COLUMNS="4" XPOSITION="30" YPOSITION="30" WIDTH="72" HEIGHT="72">
<IMAGE FULL="full_images/Abe.jpg" THUMB="thumbs/Abe.jpg" />
<IMAGE FULL="full_images/Aerith.jpg" THUMB="thumbs/Aerith.jpg" />
<IMAGE FULL="full_images/Aiai.jpg" THUMB="thumbs/Aiai.jpg" />
</GALLERY>



and the class for loading the images from the XML.
package com.classes
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.display.Stage;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class Icons extends MovieClip
	{
			var columns:Number;
			var my_x:Number;
			var my_y:Number;
			var my_thumb_width:Number;
			var my_thumb_height:Number;
			var my_images:XMLList;
			var my_total:Number;	
			
			var container_mc:MovieClip;
			
		public function Icons(can:Number)
		{

			var myXMLLoader:URLLoader = new URLLoader();
			myXMLLoader.load(new URLRequest("gallery.xml"));
			myXMLLoader.addEventListener(Event.COMPLETE, processXML);
			
			function processXML(e:Event):void
			{
				var myXML:XML = new XML(e.target.data);
				
				columns = myXML.@COLUMNS;
				my_x = myXML.@XPOSITION;
				my_y = myXML.@YPOSITION;
				my_thumb_width = myXML.@WIDTH;
				my_thumb_height = myXML.@HEIGHT;
				my_images = myXML.IMAGE;
				my_total = my_images.length(); 
				
				createContainer();
				
				callThumbs();
			}
		
		}
		
		public function createContainer():void
		{
			container_mc = new MovieClip();
			container_mc.x = my_x;
			container_mc.y = my_y;
			addChild(container_mc);
		}
		
		public function callThumbs():void
		{
			for (var i:Number = 0; i <my_total; i++)
			{
				var thumb_url = my_images [i].@THUMB;;
				var thumb_loader = new Loader();
				thumb_loader.load(new URLRequest(thumb_url));
				thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
			}
			
		}
		
		public function thumbLoaded(e:Event):void
		{
			var my_thumb:Loader = Loader(e.target.loader);
			container_mc.addChild(my_thumb);
		}
		
	}

}



I cant see any issues but keep getting the following errors

com\classes\Icons.as, Line 60 1180: Call to a possibly undefined method Loader.
com\classes\Icons.as, Line 69 1046: Type was not found or was not a compile-time constant: Loader.
com\classes\Icons.as, Line 69 1180: Call to a possibly undefined method Loader.

Any help on this matter would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem loading XML images in OOP

#2 1st Paradox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-September 12

Re: Problem loading XML images in OOP

Posted 30 September 2012 - 04:54 AM

Problem solved, I forgot to import the loader.

import flash.display.Loader;


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1