Ok, had a look.
The code is working in a sense. Rendering XML in Flash is a relatively slow process. As everything else is pretty instantaneous, it takes some time for the XML to load.
So what is happening here, is that the container_mc is resizing but then the getImages function makes it full size again because the XML is parsed after containe_mc is resized.
What we want to do is to load in the image first and THEN resize.
To do this, lets create an resize function for the image. You already have a function called resize, change that to resizeImg. Add to that a declaration for the width and height and you have your resizeImg function. In the end, it should look like this:
Code:
function resizeImg() {
container_mc._width = Stage.width
container_mc._height = Stage.height
container_mc._x = 0
container_mc._y = 0
if (container_mc._xscale > container_mc._yscale) {
container_mc._yscale = container_mc._xscale;
}
else {
container_mc._xscale = container_mc._yscale;
}
}
Now, all the resizeImg(); function inside your onEnterFrame event.
Your final code should be:
Code:
// Align Stage
Stage.align = "LT";
Stage.scaleMode = "noScale";
// resizeImg function
function resizeImg() {
container_mc._width = Stage.width
container_mc._height = Stage.height
container_mc._x = 0
container_mc._y = 0
if (container_mc._xscale > container_mc._yscale) {
container_mc._yscale = container_mc._xscale;
}
else {
container_mc._xscale = container_mc._yscale;
}
}
sizeListener = new Object();
sizeListener.onResize = function() {
trace(Stage.width)
container_mc._width = Stage.width
container_mc._height = Stage.height
if (container_mc._xscale > container_mc._yscale) {
container_mc._yscale = container_mc._xscale;
}
else {
container_mc._xscale = container_mc._yscale;
}
header._y = Stage.height - header._height;
header._x = Stage.width - header._width;
}
Stage.addListener(sizeListener);
/////////////////////////////////////////////////////////////////////////
var oldVar = 0;
var newVar = 0;
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
if (success) {
library = this.firstChild.childNodes;
maxVal = library.length;
delete my_xml;
getImage();
resizeImg();
}
else {
desc_txt.text = 'Error: XML Not Loaded';
}
};
my_xml.load('library.xml');
p = 0;
this.onEnterFrame = function() {
resizeImg();
if (container_mc._alpha<100) {
container_mc._alpha += 8;
}
};
function getImage() {
newVar = Math.floor(Math.random()*maxVal);
if (newVar == oldVar) {
getImage();
}
else {
oldVar = newVar;
container_mc._alpha = 0;
container_mc.loadMovie(library[newVar].firstChild.firstChild.nodeValue);
newVar = Math.floor(Math.random()*maxVal);
one_btn.onRelease = function() {
getImage();
}
}
}
stop();
In my testing, the random image thing doesn't really work. They way you're doing it is not really the most reliable way of doing random images.
Let me know if you need my help with fixing that up. Or you might want to keep it as is.
Bookmarks