# Photo Gallery Using XML and Flash

**URL:** <https://forum.kirupa.com/t/photo-gallery-using-xml-and-flash/182920>\
**Category:** Uncategorized\
**Created:** [March 22, 2006, 12:39pm UTC](https://forum.kirupa.com/t/photo-gallery-using-xml-and-flash/182920 "2006-03-22T12:39:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanthriller](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jeanthriller](https://forum.kirupa.com/u/jeanthriller)\
**Post date:** [March 22, 2006, 12:39pm UTC](https://forum.kirupa.com/t/photo-gallery-using-xml-and-flash/182920/1 "2006-03-22T12:39:42Z")

</div>

Dear Forum viewers,

I have a question regarding a tutorial on this website called **[COLOR=#003366]Photo Gallery[/COLOR]**[FONT=Verdana][COLOR=#003366] Using XML and Flash. what i’ve tried to accomplish with this code is to add two little features. [/COLOR][/FONT]  
[FONT=Verdana][COLOR=#003366]The first one: I want to load the picture movieclip with the size of the current Stage.size (picture.\_width = Stage.width; etc…)[/COLOR][/FONT]  
[COLOR=#003366]But when i add this to the code, the text (desc\_txt)from the picture is loaded but the picture is not. How should i code this. when openinge my webpage, the picture movieclip has the same size as my stage size. [/COLOR]  
[COLOR=#003366]The second feature. i want the first image to be a random image. ive tried to add a variable k=math.floor((math.random) \*i);[/COLOR]  
[COLOR=#003366]and changed the line picture.loadMovie(image[k], 1);[/COLOR]  
[COLOR=#003366]What happens is that, the first picture is indeed random, but when you press the refresh button, the text (desc\_txt)of the picture changes(so it does reloads a random pic) but no more picture is displayed.[/COLOR]

[COLOR=#003366]Here you will find the original code, Hope someone can help me out here![/COLOR]  
[COLOR=#003366]With Regards Jean.[/COLOR]

[COLOR=blue]function loadXML(loaded) {  
if (loaded) {  
xmlNode = this.firstChild;  
image = [];  
description = [];  
total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
image\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
description\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
}  
firstImage();  
} else {  
content = “file not loaded!”;  
}  
}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“images.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);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
}  
function prevImage() {  
if (p\>0) {  
p–;  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
function firstImage() {  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[0], 1);  
desc\_txt.text = description[0];  
picture\_num();  
}  
}  
function picture\_num() {  
current\_pos = p+1;  
pos\_txt.text = current\_pos+" / "+total;  
}[/COLOR]

[FONT=Verdana]

[/FONT]

---

<div class="post-metadata">

**Author:** ![unclesond](https://avatars.discourse-cdn.com/v4/letter/u/df788c/32.png) [@unclesond](https://forum.kirupa.com/u/unclesond)\
**Post date:** [March 22, 2006, 2:02pm UTC](https://forum.kirupa.com/t/photo-gallery-using-xml-and-flash/182920/2 "2006-03-22T14:02:24Z")

</div>

Welcome to Kirupa. I maybe able to help on the first section ,but the section section I’d be a little hazy on.

Can I ask a question first? Is the stage size going to change? I.e stretch to fit a browser or a specific size say 640x480?

i’ve got a feeling you’ll need to add an

```auto
onClipEvent (load) 
//I'm a bit hazy on the rest off the top of my head

```

to the MC it loads the image into, then once its load you can specify the size it goes to…i have the code at home, i’ll post it later.

---

<div class="post-metadata">

**Author:** ![jeanthriller](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jeanthriller](https://forum.kirupa.com/u/jeanthriller)\
**Post date:** [March 22, 2006, 2:22pm UTC](https://forum.kirupa.com/t/photo-gallery-using-xml-and-flash/182920/3 "2006-03-22T14:22:59Z")

</div>

> [@unclesond](#):
>
> Welcome to Kirupa. I maybe able to help on the first section ,but the section section I’d be a little hazy on.
> 
> Can I ask a question first? Is the stage size going to change? I.e stretch to fit a browser or a specific size say 640x480?
> 
> [COLOR=red]It will stretch to browser size. scale = no[/COLOR]
> 
> i’ve got a feeling you’ll need to add an ActionScript Code:  
> [FONT=Courier New][LEFT][COLOR=#0000ff]onClipEvent[/COLOR] COLOR=#000000[/COLOR] \</p\>  
> \<p\>[COLOR=#808080]\*//I’m a bit hazy on the rest off the top of my head \*[/COLOR]
> 
> [/LEFT]  
> [/FONT]
> 
> to the MC it loads the image into, then once its load you can specify the size it goes to…i have the code at home, i’ll post it later.

[COLOR=red]i hope to see your code! as you can see in the script it uses LoadMovie, how can we change that to an Clip Event?[/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=#ff0000]at home i also have a script that is using an clipevent for random images…maybe then this would work good too…[/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=#ff0000]we will see im looking forward to your post anyway![/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=#ff0000]cheers![/COLOR]
