Hi there,
I’m having an issue with placing images loaded from an XML file in placeholders within movie clip instances on the stage.
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="pic1.jpg" estimatedBytes="3300" load="true" />
<description title="Nature">Some of my nature photography</description>
<data>index.html</data>
<type>image</type>
</image>
<image>
<name>pic2.jpg</name>
<path url="pic2.jpg" estimatedBytes="3300" load="true" />
<description title="Wildlife">Some of my 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">Some of my 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">Some of my 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">Some of my events photography</description>
<data>index.html</data>
<type>image</type>
</image>
</gallery>
And the AS code I’m using is:
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);
for (var j:int=0; j<5; j++) {
var panelItem:ProjectPanel = new ProjectPanel;
panelItem.addEventListener(MouseEvent.CLICK, onClick);
panelItem.project_title.text = (xmlData.image[j].name);
panelItem.project_description.text = (xmlData.image[j].description);
if (j>0) {
panelItem.x = j*(panelArray[j-1].width+10);
//trace("Image = "+imageInfo);
//var imageChildren:XMLList = event.image.children();
var a:String = xmlData.image[0].path.@url.toString();
trace(a);
var imageUrlRequest:URLRequest = new URLRequest(a);
//xmlLoader.load(new URLRequest("images/slides2.xml"));
xmlLoader.load(imageUrlRequest);
//panelItem.addChild(i);
}
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();