as3ninja
05-29-2008, 04:11 PM
Hey everyone,
i could use some help on this project i need to make a photo gallery using the addChild method that is pulling from an XML feed. the problem is that all the images are random sizes and mixed between landscape and portrait. after one loads if the second image thatis click has a smaller width or height the previews image is still there and you can see it.
is there a way to remove an image when another image is brought to the stage?
would i do an if/else statement or a transition or something else??
var image:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("xml/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++)
{
image = new Loader();
image.load(new URLRequest(xmlList[i].attribute("thumb")));
image.x = i * 125 + 25;
image.y = 550;
image.name = xmlList[i].attribute("main");
addChild(image);
image.addEventListener(MouseEvent.CLICK, mainPic);
}
}
function mainPic(event:MouseEvent):void
{
image = new Loader();
image.load(new URLRequest(event.target.name));
image.x = 150;
image.y = 45;
addChild(image);
}
i could use some help on this project i need to make a photo gallery using the addChild method that is pulling from an XML feed. the problem is that all the images are random sizes and mixed between landscape and portrait. after one loads if the second image thatis click has a smaller width or height the previews image is still there and you can see it.
is there a way to remove an image when another image is brought to the stage?
would i do an if/else statement or a transition or something else??
var image:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("xml/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++)
{
image = new Loader();
image.load(new URLRequest(xmlList[i].attribute("thumb")));
image.x = i * 125 + 25;
image.y = 550;
image.name = xmlList[i].attribute("main");
addChild(image);
image.addEventListener(MouseEvent.CLICK, mainPic);
}
}
function mainPic(event:MouseEvent):void
{
image = new Loader();
image.load(new URLRequest(event.target.name));
image.x = 150;
image.y = 45;
addChild(image);
}