-
[CS3] XML Import Issue
I am having an issue with some XML loading.
It works fine after refreshing the page, however when you clear your cache and then load the page with this flash the xml does not load. I have no idea why.
Here is the code, its a little long......
Code:
// Code Created By Taj Virani
import mx.transitions.Tween;
import mx.transitions.easing.*;
// Variables
var currentImage:Number = 0;
var userImage:Number = 0;
var userControl:Boolean = false;
var xCord:Array = new Array();
var lastCord:Number = numbstart;
var stageWidth:Number = 0;
var objectwidth:Number = 0;
var numbstart:Number = 0;
var placementTotal:Number = 0;
var currentImages = 0;
var price:Array = new Array();
var price2:Array = new Array();
var dotdPrice = null;
var dotdPrice2 = null;
var g = null;
var imageLoc:Array = new Array();
var link:Array = new Array();
_root.dotdLoad = priceCode; // This is a trace
//Functions
// Alligns Dynamic Text boxes on Stage, then Turns their visibility off or on.
function activateText() {
if (_root.price[currentImage] != null) {
_root.dotdPrice = _root.price[currentImage];
_root.dotdText._visible = true;
_root.dotdText.autoSize = true;
int1 = dotdPrice[currentImage].length*4;
int3 = int1+100;
space2 = (stage.width/2)-int1+100;
space1 = (stage.width/2)-(int3*2);
_root.dotdText._x = space1;
} else {
_root.dotdText._visible = false;
}
if (_root.price2[currentImage] != null) {
_root.dotdPrice2 = _root.price2[currentImage];
_root.dotdText2._visible = true;
_root.dotdText2.autoSize = true;
int2 = dotdPrice2[currentImage].length*4;
int3 = int2+100;
space2 = (stage.width/2)-int2+100;
space1 = (stage.width/2)-(int3*2);
_root.dotdText2._x = space2;
} else {
_root.dotdText2._visible = false;
}
}
// Scales the movie to fit within a giving space in the HTML file.
function scaleMovie() {
_root.bottomBar._width = stage.width;
_root.bottomBar._y = stage.height-21;
_root.mainMovieButton._width = stage.width;
_root.mainMovieButton._height = stage.height-50;
_root.mainMovieButton._x = 0;
_root.mainMovieButton._y = 0;
_root.playerHeader._y = stage.height-18;
_root.instanceButton1._width = stage.width;
_root.instanceButton1._height = stage.height-50;
_root.instanceButton1._x = 0;
_root.instanceButton1._y = 0;
_root.dotdText._y = stage.height-50;
_root.dotdText2._y = stage.height-50;
}
// Moves the playhead on the stage
function userPlayHead() {
_root.bar.playPause_clip.gotoAndStop("play");
var xPosT:Tween = new Tween(_root.playerHeader, "_x", Regular.easeOut, _root.lastCord, _root.xCord[_root.currentImage], .5, true);
_root.lastCord = xCord[_root.currentImage];
}
// Moves the PLayhead on the stage without user input
function motionnormal() {
if (_root.userControl == false) {
activateText();
var xPosA:Tween = new Tween(_root.playerHeader, "_x", Regular.easeOut, _root.lastCord, _root.xCord[_root.currentImage], .5, true);
_root.lastCord = xCord[_root.currentImage];
}
}
// Loads the XML into Arrays
function loadXML(loaded) {
if (loaded) {
xmlNode = xmlData.firstChild;
c = 0;
total = xmlNode.childNodes.length;
total2 = total;
for (i=0; i<total2; i++) {
onOff = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
if (onOff == "DOTD") {
_root.imageLoc[c] = xmlData2.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.link[c] = xmlData2.childNodes[0].childNodes[1].firstChild.nodeValue;
_root.price[c] = xmlData2.childNodes[0].childNodes[2].firstChild.nodeValue;
_root.price2[c] = xmlData2.childNodes[0].childNodes[3].firstChild.nodeValue;
c++;
} else if (onOff != null) {
_root.imageLoc[c] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
_root.link[c] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
_root.price[c] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
_root.price2[c] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
c++;
_root.dotdLoad = "Woot, Loaded "+priceCode; //this is a trace
} else {
total = total-1;
}
}
startingPoint();
firstImage();
_root.playerHeader._x = numbstart+15;
lastCord = numbstart+15;
} else {
getURL("http://www.adobe.com/software/flash/flashpro/", "_self");
}
}
// Brings on the next image
function nextImage() {
if (userControl == false) {
if (currentImage<total-1) {
currentImage++;
if (loaded == filesize) {
_root.movie._alpha = 0;
_root.movie.loadMovie(imageLoc[currentImage],1);
}
} else {
currentImage = 0;
_root.movie._alpha = 0;
_root.movie.loadMovie(imageLoc[currentImage],1);
}
}
}
// Loads the first image onto the stage
function firstImage() {
if (loaded == filesize) {
_root.movie._alpha = 0;
_root.movie.loadMovie(imageLoc[0],1);
currentImage = 0;
}
}
// Stops the auto scroll feature, and lets the user choose which image they want to see.
function userScroll() {
if (loaded == filesize) {
_root.movie._alpha = 0;
_root.movie.loadMovie(imageLoc[currentImage],1);
_root.play_pause.gotoAndStop("play");
}
}
// Positions a number representing each graphic on the stage, also Builds buttons to those numbers
function startingPoint() {
activateText();
stagewidth = Stage.width/2;
objectwidth = ((total*17)/2);
numbstart = stagewidth-objectwidth;
i = 0;
for (var i = 0; i<total; i++) {
placementTotal = numbstart+(16*(i+1));
_root.xCord[i] = placementTotal+3;
attachMovie("timelinebutton","bottomButton"+i,i+20);
_root["bottomButton"+i]._x = placementTotal;
_root["bottomButton"+i]._y = Stage.height-20;
_root["bottomButton"+i].onRelease = function() {
_root.userControl = true;
num = Number(this._name.substr(12));
userImage = num;
currentImage = num;
userPlayHead();
userScroll();
activateText();
};
duplicateMovieClip(_root.imageNumber, "imageNumber"+i, i);
_root["imageNumber"+i]._x = placementTotal;
_root["imageNumber"+i]._y = Stage.height-20;
_root["imageNumber"+i].text = i+1;
_root.playerHeader._x = numbStart;
}
_root.imageNumber._visible = false;
attachMovie("play_pause","play_pause",90);
_root.play_pause._x = placementTotal+25;
_root.play_pause._y = Stage.height-15;
_root.play_pause.onRelease = function() {
if (userControl == false) {
_root.userControl = true;
_root.play_pause.gotoAndStop("play");
} else {
_root.userControl = false;
_root.play_pause.gotoAndStop("stop");
}
};
}
/////////////////////////////////////
// XML Load
_root.xmlData = new XML();
_root.xmlData.ignoreWhite = true;
_root.xmlData.load("http://www.parts-express.com/flash/CAT.xml");
_root.xmlData2 = new XML();
_root.xmlData2.ignoreWhite = true;
_root.xmlData2.onLoad = loadXML;
_root.xmlData2.load("http://www.parts-express.com/flash/dotd.xml");
_root.dotdLoad = priceCode + "2"; // This is a trace
// Transition Effect
this.onEnterFrame = function() {
_root.scaleMovie();
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (movie._alpha<100) {
movie._alpha += 10;
}
}
};
Any help would be awsome...I'm no pro at loading xml : /
BTW the variable priceCode is submitted with the ?priceCode = at the end the of the html. This variable passes fine based on the tests.
also, atleast that I know of...when the xml fails to load it does not show a fail value.
Last edited by Canindian; 09-09-2008 at 01:59 PM.
-
Can you post the XML files?
Also try replacing the line...
Code:
_root.xmlData2.load("http://www.parts-express.com/flash/dotd.xml");
with
Code:
_root.xmlData.onLoad = function() {
_root.xmlData2.load("http://www.parts-express.com/flash/dotd.xml");
};
This will make sure both xml files are loaded before they are used.
Last edited by dawsonk; 09-09-2008 at 03:31 PM.
-
They look like this essentially.
Code:
<imagelocs>
<pic>
<switch>x</switch> <!-- Leave Blank if not in use, else stick anything in there -->
<imageloc>http://www.parts-express.com/graphics/flash/customerService.jpg</imageloc>
<link>http://www.parts-express.com/whyPeService.cfm</link>
<price></price> <!-- Put in any text you want to display in box one, ie "Now only $50.00" -->
<price2></price2><!-- Put in any text you want to display in box two, ie "save 50%" -->
</pic>
<pic>
<switch>DOTD</switch> <!-- Leave Blank if not in use, else stick anything in there -->
<imageloc></imageloc>
<link></link>
<price></price> <!-- Put in any text you want to display in box one, ie "Now only $50.00" -->
<price2></price2><!-- Put in any text you want to display in box two, ie "save 50%" -->
</pic>
<pic>
<switch>x</switch> <!-- Leave Blank if not in use, else stick anything in there -->
<imageloc>http://www.parts-express.com/graphics/flash/HDMI.jpg</imageloc>
<link>http://www.parts-express.com/webpage.cfm?WebPage_ID=3&searchHeader=1&ObjectGroup_ID=628%20&so=1%20&filter=HDMI</link>
<price></price> <!-- Put in any text you want to display in box one, ie "Now only $50.00" -->
<price2></price2><!-- Put in any text you want to display in box two, ie "save 50%" -->
</pic>
<pic>
<switch>x</switch> <!-- Leave Blank if not in use, else stick anything in there -->
<imageloc>http://www.parts-express.com/graphics/flash/raiseBar.jpg</imageloc>
<link>http://www.parts-express.com/pe/pshowdetl.cfm?Partnumber=300-684</link>
<price></price> <!-- Put in any text you want to display in box one, ie "Now only $50.00" -->
<price2></price2><!-- Put in any text you want to display in box two, ie "save 50%" -->
</pic>
<pic>
<switch></switch> <!-- Leave Blank if not in use, else stick anything in there -->
<imageloc>http://www.parts-express.com/graphics/flash/freeShipping.jpg</imageloc>
<link>http://www.parts-express.com/freeshipping.html</link>
<price></price> <!-- Put in any text you want to display in box one, ie "Now only $50.00" -->
<price2></price2><!-- Put in any text you want to display in box two, ie "save 50%" -->
</pic>
</imagelocs>
and DOTD is generated through a Cold Fusion script...we did it this way so it only had to write 4 lines instead of the entire xml page.
it essentially looks like this though
Code:
<dotd>
<link> link to image</link>
<link2> Where it goes when you click </link2>
<price1> first price box </price>
<price2> second Price Box </price>
I think I figured it out though, you were right, it was my load that wasn't working. Since the xmldata2 was shorter then xmldata it was executing my xml load and failing. I rewrote it to this which solved the issue, but il also incorporate your code so that it makes sure both are loaded before moving on.
Thanks man.
Code:
// Loads the XML into Arrays
_root.xmlData2 = new XML();
_root.xmlData2.ignoreWhite = true;
_root.xmlData = new XML();
_root.xmlData.ignoreWhite = true;
xmlData.onLoad = function(loaded) {
if (loaded) {
xmlNode = xmlData.firstChild;
c = 0;
total = xmlNode.childNodes.length;
total2 = total;
for (i=0; i<total2; i++) {
onOff = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
if (onOff == "DOTD") {
_root.imageLoc[c] = xmlData2.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.link[c] = xmlData2.childNodes[0].childNodes[1].firstChild.nodeValue;
_root.price[c] = xmlData2.childNodes[0].childNodes[2].firstChild.nodeValue;
_root.price2[c] = xmlData2.childNodes[0].childNodes[3].firstChild.nodeValue;
c++;
} else if (onOff != null) {
_root.imageLoc[c] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
_root.link[c] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
_root.price[c] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
_root.price2[c] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
c++;
} else {
total = total-1;
}
}
startingPoint();
firstImage();
_root.playerHeader._x = numbstart+15;
lastCord = numbstart+15;
}
};
_root.xmlData2.load("http://www.parts-express.com/flash/dotd.xml?cachebuster="+new Date().getTime());
xmlData2.onLoad = function(loaded) {
_root.xmlData.load("http://www.parts-express.com/flash/"+priceCode+".xml?cachebuster="+new Date().getTime());
}
Last edited by Canindian; 09-10-2008 at 03:25 PM.
Reason: Incomplete Code Tags
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
|