-
load XML from another XML
Hello,
So...
On a frame, a have 2 amounts of code. The first one is for the XML driven menu, and the second one is for the image galleries (it's a portfolio page).
So there's only one gallery on the stage, wich loads an XML file. The buttons are actually categories of galleries, and, onRelease they load another XML file for the gallery (each button corespond to a gallery). What I want is to automatically load the first XML from the portfolio.xml into the gallery.
In this case, I want the "web design portfolio.xml" from the portfolio.xml to load automatically. (onLoad of the portfolio.xml)
THE XML FILE FOR THE BUTTONS, called portfolio.xml
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<menu>
<menu name='web design' loadXML='web design portfolio.xml' />
<menu name='illustration' loadXML='illustration portfolio.xml' />
<menu name='motion' loadXML='motion portfolio.xml' />
</menu>
THE ACTION SCRIPT
PHP Code:
stop();
startPosY = 220;
startPosX = 200;
btnHeightVal = 19
var portfolioXML:XML = new XML();
portfolioXML.ignoreWhite = true;
var loadXMLs:Array = new Array();
var names:Array = new Array();
portfolioXML.onLoad = function(status) {
if (status) {
var linkname:Array = this.firstChild.childNodes;
len = linkname.length
for (i=0; i<len; i++) {
names.push(linkname[i].attributes.name);
loadXMLs.push(linkname[i].attributes.loadXML);
_root.attachMovie("button","btnp"+i,_root.getNextHighestDepth());
_root["btnp"+i]._y = startPosY;
_root["btnp"+i]._x = startPosX;
startPosY = startPosY+btnHeightVal;
_root["btnp"+(i)].txt_btn_mc.nameTxt.text = (names[i]);
_root["btnp"+(i)].onRollOver = btnOver;
_root["btnp"+(i)].onRollOut = btnOut;
_root["btnp"+(i)].onRelease = btnReleased;
import mx.transitions.Tween;
import mx.transitions.*;
import mx.transitions.easing.*;
TransitionManager.start(back_mc_portfolio, {type:Fade, direction:Transition.IN, duration:1, easing:Strong.easeOut});
TransitionManager.start(_root["btnp"+i], {type:Fly, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:8});
TransitionManager.start(trick_btn_second, {type:Fly, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:8});
new Tween(trick_btn_second,"_alpha",Strong.easeOut,trick_btn_second._alpha,100,6,true)
back_btn_portfolio._visible = true
}
} else {
errorTxt="Error Loading XML"
}
};
/////////////////////////////////////////////////////////////////
portfolioXML.load("portfolio.xml");
////////////////////////////////////////////////////////////////////
function btnOver() {
this.gotoAndPlay(2);
}
function btnOut() {
this.gotoAndPlay(11);
}
function btnReleased() {
trick_btn_second._y = this._y
trick_btn_second._x = this._x
import mx.transitions.*;
import mx.transitions.easing.*;
TransitionManager.start(desc_mc, {type:Iris, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:5, shape:Iris.SQUARE});
var currentBtn:String = this._name;
var currentXML:String = currentBtn.substring(4, 6);
xmlData.load(loadXMLs[currentXML]);
}
attachMovie("trick_btn_second", "trick_btn_second",0)
trick_btn_second._y = startPosY
trick_btn_second._x = startPosX
trick_btn_second._height=16.5
trick_btn_second._alpha=0
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
thumbnails = [];
link = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
thumbnails[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
link[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
thumbnails_fn(i);
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
///////////////////////////////////////////////////////
xmlData.load("web design portfolio.xml");
///////////////////////////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
Key.addListener(listen);
previous_btn.onRelease = function() {
prevImage();
};
next_btn.onRelease = function() {
nextImage();
};
p = 0;
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 10;
}
}
};
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
flyout_mc.desc_txt.text = description[p];
picture_num();
}
}
}
function prevImage() {
if (p>0) {
p--;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
flyout_mc.desc_txt.text = description[p];
picture_num();
}
}
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
flyout_mc.desc_txt.text = description[0];
picture_num();
}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}
function thumbNailScroller() {
// thumbnail code!
this.createEmptyMovieClip("tscroller", 1000);
scroll_speed = 10;
tscroller.onEnterFrame = function() {
if ((_root._ymouse>=thumbnail_mc._y) && (_root._ymouse<=thumbnail_mc._y+thumbnail_mc._height)) {
if ((_root._xmouse>=(hit_right._x-40)) && (thumbnail_mc.hitTest(hit_right))) {
thumbnail_mc._x -= scroll_speed;
} else if ((_root._xmouse<=(hit_left._x+40)) && (thumbnail_mc.hitTest(hit_left))) {
thumbnail_mc._x += scroll_speed;
}
} else {
delete tscroller.onEnterFrame;
}
};
}
function thumbnails_fn(k) {
thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth());
tlistener = new Object();
tlistener.onLoadInit = function(target_mc) {
target_mc._x = hit_left._x+(target_mc._width+5)*k;
target_mc.pictureValue = k;
target_mc.onRelease = function() {
p = this.pictureValue-1;
nextImage();
};
target_mc.onRollOver = function() {
import mx.transitions.*;
import mx.transitions.easing.*;
new Tween(this,"_alpha",Regular.easeOut,this._alpha,50,0.5,true)
thumbNailScroller();
};
target_mc.onRollOut = function() {
new Tween(this,"_alpha",Regular.easeOut,this._alpha,100,0.5,true)
};
};
image_mcl = new MovieClipLoader();
image_mcl.addListener(tlistener);
image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);
}
btn_btn.onRelease = function () {
getURL(link[p], "_blank")
picture_num()
}
btn_btn.onRollOver = function () {
new Tween(flyout_mc,"_y",Strong.easeOut,flyout_mc._y,145.6,0.7,true)
}
btn_btn.onRollOut = function () {
new Tween(flyout_mc,"_y",Strong.easeOut,flyout_mc._y,495,0.7,true)
}
flyout_mc.setMask(mask_mc)
flyout_mc._y = 495
thumbnail_mc._x = 11.4
import mx.transitions.*;
import mx.transitions.easing.*;
TransitionManager.start(flyout_mc, {type:Fly, direction:Transition.IN, duration:1.5, easing:Strong.easeOut, startPoint:8});
TransitionManager.start(next_mc, {type:Fly, direction:Transition.IN, duration:1.5, easing:Strong.easeOut, startPoint:8});
TransitionManager.start(previous_mc, {type:Fly, direction:Transition.IN, duration:1.5, easing:Strong.easeOut, startPoint:8});
back_btn_portfolio._visible = false
back_mc_portfolio._visible = false
On line 10 o the AS is the onLoad statement for the buttons.
On the 95 line of the AS the XML for the first gallery is loaded. That's what I would like to change and make it automatically, so the user does not have to edit the .fla file in order to change the first XML file for the gallery that is being loaded.
I would really appreciate any kind of help please. Thank you in advance
-
Maybe try something like this...
The following shows one line that needs to be added and one line that needs to be commented out. (Didn't copy all of the code here just so it will be easier to see where the changes are.)
Code:
portfolioXML.onLoad = function(status) {
if (status) {
var linkname:Array = this.firstChild.childNodes;
len = linkname.length
for (i=0; i<len; i++) {
names.push(linkname[i].attributes.name);
loadXMLs.push(linkname[i].attributes.loadXML);
_root.attachMovie("button","btnp"+i,_root.getNextHighestDepth());
_root["btnp"+i]._y = startPosY;
_root["btnp"+i]._x = startPosX;
startPosY = startPosY+btnHeightVal;
_root["btnp"+(i)].txt_btn_mc.nameTxt.text = (names[i]);
_root["btnp"+(i)].onRollOver = btnOver;
_root["btnp"+(i)].onRollOut = btnOut;
_root["btnp"+(i)].onRelease = btnReleased;
import mx.transitions.Tween;
import mx.transitions.*;
import mx.transitions.easing.*;
TransitionManager.start(back_mc_portfolio, {type:Fade, direction:Transition.IN, duration:1, easing:Strong.easeOut});
TransitionManager.start(_root["btnp"+i], {type:Fly, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:8});
TransitionManager.start(trick_btn_second, {type:Fly, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:8});
new Tween(trick_btn_second,"_alpha",Strong.easeOut,trick_btn_second._alpha,100,6,true)
back_btn_portfolio._visible = true
}
// add here
xmlData.load(loadXMLs[0]);
} else {
errorTxt="Error Loading XML"
}
};
/////////////////////////////////////////////////////////////////
portfolioXML.load("portfolio.xml");
////////////////////////////////////////////////////////////////////
function btnOver() {
this.gotoAndPlay(2);
}
function btnOut() {
this.gotoAndPlay(11);
}
function btnReleased() {
trick_btn_second._y = this._y
trick_btn_second._x = this._x
import mx.transitions.*;
import mx.transitions.easing.*;
TransitionManager.start(desc_mc, {type:Iris, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:5, shape:Iris.SQUARE});
var currentBtn:String = this._name;
var currentXML:String = currentBtn.substring(4, 6);
xmlData.load(loadXMLs[currentXML]);
}
attachMovie("trick_btn_second", "trick_btn_second",0)
trick_btn_second._y = startPosY
trick_btn_second._x = startPosX
trick_btn_second._height=16.5
trick_btn_second._alpha=0
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
thumbnails = [];
link = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
thumbnails[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
link[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
thumbnails_fn(i);
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
////////////////// Comment out the line below
// xmlData.load("web design portfolio.xml");
///////////////////////////////////////////////////////
listen = new Object();
-
-
It needs to be in the onLoad function because flash continues processing without waiting for a function to finish. So placing it outside means the 'onLoad' kicks off and then proceeds to the next line, etc. Which means outside the function at this point loadXMLs[0] has no data and as you discovered it didn't work.
HTH
-
That makes sense. Too bad I didn't figure it out myself
THANK YOU SO MUCH FOR HELPING ME
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
|