-
AS2 - Need help with importing text from XML
I can't seem to figure out why only one out of the five text fields show when I export my fla. The title and images work fine but none of the other descriptors are not working. What am I doing wrong? I checked my instance names and they all match. I've tried using .text and .HTMLText in the AS and nothing. Any help would be greatly appreciated.
AS2
import mx.transitions.Tween;
import mx.transitions.easing.*;
var galleryTitle:String;
var totalImages:Number;
var autoSS:Number;
var CSI:Number; // Current Showed Image
var NItL:Number = 0; // Next Image to Load
var MCLs:Array = new Array();
var targets:Array = new Array();
var imgLoaded:Array = new Array();
var imgPaths:Array = new Array();
var loadList:Object = new Object();
var navList:Object = new Object();
var sleep:Boolean = true;
var onFocus:Boolean = false;
var imagesXML:XML = new XML();
imagesXML.ignoreWhite = true;
var XMLLoaded:Boolean = false;
var initCall:Boolean = false;
//var border:MovieClip;
var navigation:MovieClip;
/* ---------------------------------------------------------------------- */
imagesXML.load("./gallery.xml");
onEnterFrame = function () {
if (XMLLoaded) {
if (!initCall) {
initCall = true;
//border = this.attachMovie("border", "borderMovie", totalImages+2);
//border._x = 0;
//border._y = 238.2; // 300
navigation = this.attachMovie("nav", "navMovie", totalImages+1);
navigation._x = 0;
navigation._y = 446.6; // 300
for (i=0; i<totalImages; i++) {
MCLs[i] = new MovieClipLoader();
MCLs[i].addListener(loadList);
imgLoaded[i] = 0;
var newTarget = this.attachMovie("target", "target" + String(i), totalImages-1-i);
targets[i] = newTarget;
targets[i]._alpha = 0;
targets[i]._x = 25.5;
targets[i]._y = 1.40;
}
loadImage(0);
navigation.changeImgShow();
}
if (imgLoaded[0]) {
var showTw:Tween = new Tween(targets[0], "_alpha", none, 0, 100, 20, false);
CSI = 0;
loading.SHLoading("hide");
delete this.onEnterFrame;
}
}
}
imagesXML.onLoad = function () {
images = this.firstChild.childNodes;
for(var i=0; i<images.length; i++) {
imgPaths.push(images[i].attributes.path);
}
totalImages = imgPaths.length;
autoSS = this.firstChild.attributes.slideshow == "true" ? 1 : 0;
intervalSS = parseInt(this.firstChild.attributes.interval)*1000 ;
galleryTitle = this.firstChild.attributes.title;
client_txt.text = this.childNodes.attributes.client;
description_txt.text = this.childNodes.attributes.description;
state_txt.text = this.childNodes.attributes.state;
XMLLoaded = true;
}
My XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery title="Atriums" slideshow="false" interval="5">
<image path="atrium/atrium1.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium2.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium3.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium4.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium5.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium6.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
<image path="atrium/atrium7.jpg" client="name" description="Interior" state="Phoenix, Arizona"/>
</gallery>
-
Code:
imagesXML.onLoad = function() {
images = this.firstChild.childNodes;
for (var i = 0; i<images.length; i++) {
imgPaths.push(images[i].attributes.path);
}
totalImages = imgPaths.length;
autoSS = this.firstChild.attributes.slideshow == "true" ? 1 : 0;
intervalSS = parseInt(this.firstChild.attributes.interval)*1000;
galleryTitle = this.firstChild.attributes.title;
client_txt.text = this.firstChild.childNodes[0].attributes.client;
description_txt.text = this.firstChild.childNodes[0].attributes.description;
state_txt.text = this.firstChild.childNodes[0].attributes.state;
XMLLoaded = true;
};
-
Originally Posted by dawsonk
Code:
imagesXML.onLoad = function() {
images = this.firstChild.childNodes;
for (var i = 0; i<images.length; i++) {
imgPaths.push(images[i].attributes.path);
}
totalImages = imgPaths.length;
autoSS = this.firstChild.attributes.slideshow == "true" ? 1 : 0;
intervalSS = parseInt(this.firstChild.attributes.interval)*1000;
galleryTitle = this.firstChild.attributes.title;
client_txt.text = this.firstChild.childNodes[0].attributes.client;
description_txt.text = this.firstChild.childNodes[0].attributes.description;
state_txt.text = this.firstChild.childNodes[0].attributes.state;
XMLLoaded = true;
};
Thanks Dawsonk but it still isn't working. Any other thoughts?
-
What are the output results when adding the traces below?
Code:
imagesXML.onLoad = function() {
images = this.firstChild.childNodes;
for (var i = 0; i<images.length; i++) {
imgPaths.push(images[i].attributes.path);
}
totalImages = imgPaths.length;
autoSS = this.firstChild.attributes.slideshow == "true" ? 1 : 0;
intervalSS = parseInt(this.firstChild.attributes.interval)*1000;
galleryTitle = this.firstChild.attributes.title;
trace(client_txt.text);
trace(this.firstChild.childNodes[0]);
client_txt.text = this.firstChild.childNodes[0].attributes.client;
description_txt.text = this.firstChild.childNodes[0].attributes.description;
state_txt.text = this.firstChild.childNodes[0].attributes.state;
XMLLoaded = true;
};
Can you post the missing code for the functions...
Code:
loadImage(0);
navigation.changeImgShow();
loading.SHLoading("hide");
-
Okay, here's what the trace returned:
Code:
undefined
<image path="atrium/atrium1.jpg" client="SCF Arizona - Accounting & Finance Department" description="Interior Remodel - 8,000 sf" state="Phoenix, Arizona" />
So, it looks like the AS is okay but something is wrong with the XML?
Here's the code for the functions
Code:
// -- Load Imagers -- //
function loadImage(image:Number):Void {
MCLs[image].loadClip(imgPaths[image], targets[image]);
}
loadList.onLoadComplete = function(evn:Object) {
var loadedImg:Number = parseInt(evn._name.substr(6, 1));
imgLoaded[loadedImg] = 1;
if (loadedImg < totalImages) {
loadImage(loadedImg + 1);
}
}
// -- Switch Images -- //
function switchImages(hideImg:Number, showImg:Number):Void {
if (imgLoaded[showImg]) {
var hideTw:Tween = new Tween(targets[hideImg], "_alpha", none, targets[hideImg]._alpha, 0, 20, false);
var showTw:Tween = new Tween(targets[showImg], "_alpha", none, targets[showImg]._alpha, 100, 20, false);
CSI = showImg;
navigation.changeImgShow();
} else {
loading.SHLoading("show");
var hideTw:Tween = new Tween(targets[hideImg], "_alpha", none, targets[hideImg]._alpha, 0, 20, false);
if (CSI == totalImages - 2) { // Check for the last Image.
navigation.nextBtn.action("disable"); // Only by nextBtn disable.
}
navigation.changeImgShow();
onEnterFrame = function() {
if (imgLoaded[showImg]) {
loading.SHLoading("hide");
var showTw:Tween = new Tween(targets[showImg], "_alpha", none, targets[showImg]._alpha, 100, 20, false);
CSI = showImg;
navigation.changeImgShow();
delete this.onEnterFrame;
}
}
}
}
// -- Navigation -- //
Mouse.addListener(navList);
//var initSleep = setInterval(checkSleep, 1500);
//navList.onMouseMove = function() {
// if (sleep) {
// if (navigation._y != 268) {
// navMove(268);
// sleep = false;
// }
//}
//function checkSleep():Void {
// if (sleep && !onFocus) {
// navMove(300);
// } else {
// sleep = true;
// }
//}
//function navMove(newY:Number):Void {
// var moveNavTw:Tween = new Tween(navigation, "_y", Strong.easeInOut, navigation._y, newY, 15, false);
//}
function prevImg():Void {
if (imgLoaded[0] && CSI != 0) {
switchImages(CSI, CSI-1);
if (Math.round(navigation.nextBtn.arr._alpha - navigation.enAlpha)) { // Activation Check
navigation.nextBtn.action("enable");
}
if (CSI == 0) { // Check for the first Image
navigation.prevBtn.action("disable");
}
}
}
function nextImg():Void {
if (imgLoaded[0] && CSI < totalImages - 1) {
switchImages(CSI, CSI+1);
if (Math.round(navigation.prevBtn.arr._alpha - navigation.enAlpha)) { // Activation Check
navigation.prevBtn.action("enable");
}
if (CSI == totalImages - 1) { // Check for the last Image
navigation.nextBtn.action("disable");
}
}
}
function nextImgSS():Void {
if (imgLoaded[0]) {
if (CSI == totalImages - 1) {
switchImages(CSI, 0);
} else {
switchImages(CSI, CSI+1);
}
if(CSI == totalImages - 1) {
navigation.nextBtn.action("disable");
} else if (CSI == 0) {
navigation.prevBtn.action("disable");
navigation.nextBtn.action("enable");
} else {
if (Math.round(navigation.prevBtn.arr._alpha - navigation.enAlpha)) { // Activation Check
navigation.prevBtn.action("enable");
}
}
}
}
-
Originally Posted by leah5569
Okay, here's what the trace returned:
Code:
undefined
<image path="atrium/atrium1.jpg" client="SCF Arizona - Accounting & Finance Department" description="Interior Remodel - 8,000 sf" state="Phoenix, Arizona" />
The result of the first trace statement 'undefined' is telling you that it can't find the text field, so check the path and spelling.
The result of the second trace statement is as expected, so the XML appears to be fine.
-
Originally Posted by dawsonk
The result of the first trace statement 'undefined' is telling you that it can't find the text field, so check the path and spelling.
The result of the second trace statement is as expected, so the XML appears to be fine.
Okay, I think I found the culprit. There's actions on the navigation and I think I need to add the text fields to it. I took a stab at it and at least get an "undefined" showing where one of the text fields is. I'm a little confused about the Parent / child relationship though. I think client, description and state are a child of Gallery??
Code:
var disAlpha:Number = 20;
var enAlpha:Number = 60;
var ovAlpha:Number = 90;
/*-----*/
base.onRollOver = function() {
_root.onFocus = true;
}
base.onRollOut = function() {
_root.onFocus = false;
}
base.useHandCursor = false;
/*-----*/
prevBtn.arr._alpha = disAlpha;
prevBtn.enable = false;
nextBtn.enable = true;
galleryTitle.text = _parent.galleryTitle;
client_txt.text = _parent.client_txt;
description_txt.text = _parent.description_txt;
state_txt.text = _parent.state_txt;
//imgShow.text = "Image 1 / " + _parent.totalImages;
prevBtn.onRelease = function() {
_parent.prevImg();
}
nextBtn.onRelease = function() {
_parent.nextImg();
}
function changeImgShow() {
imgShow.text = "Image " + String(_parent.CSI + 1) + " / " + _parent.totalImages;
}
SWBtn.onRelease = function() {
tick.changeTick();
}
SWBtn.onRollOver = function() {
_root.onFocus = true;
}
SWBtn.onRollOut = function() {
_root.onFocus = false;
}
-
Flash Genie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|