Hi there,
I’m having an issue with placing images loaded from an XML file in placeholders within movie clip instances on the stage.
It’ll load an image onto stage, but only one image instead of the lot. I’m kinda at a loss at the moment.
Hope someone can help me with this.
Many thanks in advance.
My XML file is:
<?xml version="1.0" encoding="utf-8"?>
<gallery>
<image>
<name>pic1.jpg</name>
<path url="images/pic1.jpg" estimatedBytes="3300" load="true" />
<description title="Nature">Nature photography</description>
<data>index.html</data>
<type>image</type>
</image>
<image>
<name>pic2.jpg</name>
<path url="images/pic2.jpg" estimatedBytes="3300" load="true" />
<description title="Wildlife">Wildlife photography</description>
<data>index.html</data>
<type>image</type>
</image>
<image>
<name>pic3.jpg</name>
<path url="images/pic3.jpg" estimatedBytes="3300" load="true" />
<description title="Architecture">Architecture photography</description>
<data>index.html</data>
<type>image</type>
</image>
<image>
<name>pic4.jpg</name>
<path url="images/pic4.jpg" estimatedBytes="3300" load="true" />
<description title="Motor Sports">Motor sports photography</description>
<data>index.html</data>
<type>image</type>
</image>
<image>
<name>pic5.jpg</name>
<path url="images/pic5.jpg" estimatedBytes="3300" load="true" />
<description title="Events">Events photography</description>
<data>index.html</data>
<type>image</type>
</image>
</gallery>
And the AS:
import com.greensock.TweenLite;
import com.greensock.easing.Back;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import com.greensock.events.LoaderEvent;
import flash.display.Sprite;
import flash.text.*;
// CONTAINER FOR SCROLLING
var panelContainer:Sprite = new Sprite;
addChild(panelContainer);
// INITIAL VARIABLES
//var captionArray:Array = new Array();
//var imageArray:Array = new Array();
var currentButton:Object = new Object;
var selectedSection:Number = 0;
//var myImage:Array = new Array();
function progressHandler(event:LoaderEvent):void {
trace("progress: " + event.target.progress);
}
var xmlLoader:URLLoader = new URLLoader();
var xmlData: XML;
//Adding an event listener to notify when loading is completed
xmlLoader.addEventListener(Event.COMPLETE,ParseXML);
//xmlLoader.addEventListener(Event.COMPLETE,ParseXML2);
//Load the XML file
xmlLoader.load(new URLRequest("images/slides2.xml"));
function ParseXML(event:Event):void {
//function ParseXML(xmlData:XML):void {
var panelArray:Array = new Array();
xmlData = new XML(event.target.data);
var lengthDoc = xmlData.image.name.length();
var xmlLoader = new Loader();
for (var j:int=0; j<lengthDoc; j++) {
var panelItem:ProjectPanel = new ProjectPanel;
panelItem.addEventListener(MouseEvent.CLICK, onClick);
panelItem.project_title.text = (xmlData.image[j].description.@title);
panelItem.project_description.text = (xmlData.image[j].description);
var a:String = xmlData.image[j].path.@url.toString();
trace(a);
var imageUrlRequest:URLRequest = new URLRequest(a);
xmlLoader.load(imageUrlRequest);
panelItem.project_image.MovieClip = (xmlLoader);
// panelItem.project_image.addChild(xmlLoader);
if (j>0) {
panelItem.project_image.addChild(xmlLoader);
panelItem.x = j*(panelArray[j-1].width+10);
//trace("Image = "+imageInfo);
//var imageChildren:XMLList = event.image.children();
}
panelArray.push(panelItem);
// adding Items as children to Container
panelContainer.addChild(panelItem);
}
}
function ParseXML2(imageData2:XML):void {
trace("------------------------");
trace("XML Output");
trace("------------------------");
var imageChildren:XMLList = imageData2.image.children();
for each (var imageData2:XML in imageChildren) {
if (imageData2.name() == "name") {
// trace(imageData2);
}
}
}
function errorHandler(event:LoaderEvent):void {
trace("error occured with " + event.target + ": " + event.text);
}
function onClick(evt:MouseEvent):void {
// tween all panels below visible area when clicking on projectPanel
TweenLite.to(panelContainer, 0.5, {y:stage.stageHeight+250, ease:Back.easeIn});
// running function on the main timeline
MovieClip(this.parent).addFullPanel();
}
// slide the panels back up on closing the single panel project
function slideUp():void {
TweenLite.to(panelContainer, 0.5, {y:0, ease:Back.easeOut});
}
// HORIZONTAL SCROLLING
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onMove(evt:MouseEvent):void {
// scroll only if fullprojectpanelup is false to prevent from interfering with transitions
if (MovieClip(this.parent).fullProjectPanelUp==false) {
TweenLite.to(panelContainer, 0.3, {x:-(stage.mouseX/980)*panelContainer.width+stage.stageWidth/2});
}
}
stop();