Problem Integrating 2 Tutorials

[left]Hi there![/left]
[left] [/left]

[left]First of all, I wanted to say thank you to all of you who post here regularly and provide tutorials for all us n00bs to benefit from. I have learned more about Flash MX from this site than I ever would have reading a book about the topic.[/left]
[left] [/left]

[left]I am in the process of creating a little personal site, and I am using a couple of tutorials found on this site to do so. The first is “The Complete Flash Site” tutorial (http://www.kirupa.com/developer/mx/full_site.htm) and the second is “Creating a Photo Gallery” ([url=“http://www.kirupa.com/developer/mx/photogallery.htm”]http://www.kirupa.com/developer/mx/photogallery.htm).[/left]

[left] [/left]
[left]Anyway. I’ve successfully created both and they run fine on their own. My problem begins when I try to integrate the two. I’ve created the basic navigational structure for my site (i.e. “Home”, “Contact”, etc…) and it all works fine. Each page being linked too on the navigation is a published .swf file that gets loaded into the movie clip “contents” which is an instans of the main window. This works just great for all the buttons EXCEPT for “gallery”[/left]

[left]My gallery works fine on it’s own. The pictures show up as they are supposed to, and fade in and out, etc… The code (by suprabeener) for the gallery is as follows:[/left]

[left] [/left]
[left]//Code written by sbeener (suprabeener)[/left]
/*
i wrote this code, but you can use and abuse it however you like.
the methods are defined in the order which they occur to make it
easier to understand.
*/
// variables ------------------------------------------
// put the path to your pics here, include the slashes (ie. “pics/”)
// leave it blank if they’re in the same directory
this.pathToPics = “…/graphics/”;
// fill this array with your pics
this.pArray = [“image0.jpg”, “image1.jpg”, “image2.jpg”, “image3.jpg”, “image4.jpg”, “image5.jpg”, “image6.jpg”, “image7.jpg”, “image8.jpg”, “image9.jpg”];
this.fadeSpeed = 20;
this.pIndex = 0;
// MovieClip methods ----------------------------------
// d=direction; should 1 or -1 but can be any number
//loads an image automatically when you run animation
loadMovie(this.pathToPics+this.pArray[0], _root.photo);
MovieClip.prototype.changePhoto = function(d) {
// make sure pIndex falls within pArray.length
this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {
this.pIndex += this.pArray.length;
}
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.photo._alpha>this.fadeSpeed) {
this.photo._alpha -= this.fadeSpeed;
} else {
this.loadPhoto();
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.photo;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.photo.getBytesLoaded();
t = this.photo.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.photo._alpha<100-this.fadeSpeed) {
this.photo._alpha += this.fadeSpeed;
} else {
this.photo._alpha = 100;
this.onEnterFrame = null;
}
};
// Actions -----------------------------------------
// these aren’t necessary, just an example implementation
this.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
this.changePhoto(-1);
} else if (Key.getCode() == Key.RIGHT) {
this.changePhoto(1);
}
};
Key.addListener(this);

[left] [/left]
[left]-------------------------------------------------------------------------[/left]

[left] [/left]
[left]When I click on my “gallery” button, instead of loading in the designated area (like the other links do), my gallery loads in the top left corner of the screen, and I only see part of the .swf page (the first .jpeg I am trying to display, without the navigation arrows, etc…). I also don’t see any of my “main” navigation, etc…[/left]
[left] [/left]

[left]The action code on the “gallery” button is the same as the others:[/left]

[left] [/left]
[left]on (release) {[/left]
_root.contents.loadMovie(“gallery.swf”);
}

[left] [/left]
[left]Any ideas what may be causing this? I’ve tried multiple workarounds, but none work very well. Any help is appreciated :)[/left]

[left] [/left]
[left]-Swedish Mike[/left]

Welcome to kirupa forum=)

If you look in the code you’ll 2 times “_root.photo”. Change those in “this.photo”. The same for your buttons, though you can do it there with skipping the “_root”.
More on _root etc
http://www.kirupa.com/developer/actionscript/tricks/root_parent_this.htm

scotty(-:

THANK YOU! THANK YOU! THANK YOU!

I have been going NUTS trying to figure this out. I really appreciate the quick reply. Now I just need to do some additional reading about _root to fully understand why it didn’t work.

In the meantime, I have another quick questions. The image itself keeps “resizing” a little when I go from one to the next. They are all the same size, and I have made sure that the area they are displayed in is the same (and that the scale is set to 100%, 100%).

What could be causing that?

-Swedish Mike

Flash has some problems with _alpha when it’s set to 100.
Try this, maybe it helps:)

MovieClip.prototype.fadeIn = function() {
 if (this.photo._alpha<98-this.fadeSpeed) {
 this.photo._alpha += this.fadeSpeed;
 } else {
 this.photo._alpha = 99;
 this.onEnterFrame = null;
}
}

scotty(-:

It works wonders!

You certainly know your stuff. Thanks for all the help!

-Swedish Mike

no problem=)