header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
meoden8x
Points:110
Posts:0

8/2/2010 2:56:51 AM

Title: Loaded images's positions are incorrect


My gallery project containt a main class as follow:



package  
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Tuan
	 */
	public class Main extends MovieClip
	{
		//Declare member variables here
		var urlLoader:URLLoader;
		var xml:XML;
		var xmlPath:URLRequest;
		var imgPath:URLRequest;
		var x_counter:Number = 0;
		var y_Counter:Number = 0;
		var initX:Number = 180;
		var initY:Number = 250;
		var thumbnail_Width:Number = 200;
		var thumbnail_Height:Number = 150;
		var spaceW:Number = 10;
		var spaceH:Number = 12;
		var offset:int = 0;
		var loader:Loader;
		
		//Constructor here
		public function Main() 
		{
			xmlPath = new URLRequest("Demo.xml");
			urlLoader = new URLLoader();
			urlLoader.load(xmlPath);
			urlLoader.addEventListener(Event.COMPLETE, processXML);
			btnSearch.addEventListener(MouseEvent.CLICK, searchClick);
			next.buttonMode = true;
			prev.buttonMode = true;
			btnSearch.buttonMode = true;
		}
		
		//Process loaded xml file
		public function processXML(e:Event):void
		{
			xml = new XML(e.target.data);
			for (var i:int = 0; i < xml.game.length(); i++)
			{
				loadThumb(xml.game[i].@thumb);
			}
		}
		
		//Load thumbnails here
		public function loadThumb(path:String)	
		{
			loader = new Loader();
			loader.name = path;
			imgPath = new URLRequest(path);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbnail_Loaded);
			loader.load(imgPath);
			trace("======"+loader.name);

		}
		
		//Process loaded thumbnails here
		public function processThumb(e:Event):void
		{	
			/*var my_thumb:Loader = Loader(e.target.loader);
			
			if (my_thumb.name == loader.name)
			{
			
				var container:mcContainer = new mcContainer();
				addChild(container);
				container.addChild(my_thumb);
				container.x = (thumbnail_Width + spaceW) * x_counter + initX;
				container.y = (thumbnail_Height +spaceH) * y_Counter + initY;
				container.buttonMode = true;
				container.addEventListener(MouseEvent.CLICK, containerClick);
				
				if (x_counter + 1 < 3)
				{
					x_counter++;
				}
				
				else 
				{
					x_counter = 0;
					y_Counter++;
				}
				
				offset++;
				container.txtSrc.text = xml.game[offset - 1].@scr;	
				trace(offset);
			}*/
		}
		
		//The event occured when user click the search button
		public function searchClick(e:MouseEvent):void
		{
			//push query to the server
		}
		
		//Container click event
		public function containerClick(e:Event):void
		{
			var myContainer:mcContainer = e.currentTarget as mcContainer;
			trace(myContainer.txtSrc.text);
		}
	}
}

This file load image in the xml file as follow: <?xml version="1.0" encoding="utf-8" ?> <gameList> <game id="435" thumb="image/buoc_nhay_vui_nhon.jpg" scr="image/buoc_nhay_vui_nhon_v2.swf" /> <game id="447" thumb="image/olympic_boi_loi.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000390/flash/olympic_boi_loi.swf" /> <game id="454" thumb="image/tang_bong_bai_bien.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000397/flash/tang_bong_bai_bien.swf" /> <game id="453" thumb="image/nhay_cau_nghe_thuat.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000396/flash/nhay_cau_nghe_thuat.swf" /> <game id="452" thumb="image/gau_meo_cuu_ho.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000395/flash/gau_meo_cuu_ho.swf" /> <game id="451" thumb="image/quyen_anh_hang_ruoi.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000394/flash/quyen_anh_hang_ruoi.swf" /> <game id="450" thumb="image/lulu_thien_xa.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000393/flash/lulu_thien_xa.swf" /> <game id="449" thumb="image/vo_si_karatedo.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000392/flash/vo_si_karatedo.swf" /> <game id="448" thumb="image/doi_dau_san_co.jpg" scr="http://www.socnhi.com/socnhiAdmin/images.game/GM000391/flash/doi_dau_san_co.swf" /> </gameList> I don't know why the loaded images's postitions are incorrect, please help me.



1
Davis
Points: 780
Posts:0
8/2/2010 5:01:30 AM



In your "thumbnail_Loaded" function you can set the x and y of the loaded thumbnail images

2
bob_senior
Points: 1320
Posts:0
8/2/2010 5:32:43 AM



if all the images are of the same size then you should set there x,y positions to 0 when there loading complete listener is triggered


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 2+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions