XML Data Remains Through Scenes

Using Flash 8, AS 1/2.

Here’s what I’m trying to do…

I’ve got a slide show sort of thing. Five different scenes. You can navigate scene to scene with simple button navigation. One half of the slide show displays a constant image. The other side displays a different image depending on the scene you’re in.

Along with each different image, there is a caption for each image. When you click on the caption, text from an external XML file is displayed.

I got that far, and I thought everything was working perfectly. Then I changed scenes.

The scenario I’m at right now:

Scene 1 loads. I click on the caption. The text from the external XML file displays.

Click the navigation button to go to Scene 2. The text from the external XML file that displayed when I clicked Scene 1’s caption is displayed.

If I click through the rest of the scenes, the text that was displayed when I clicked on Scene 1’s caption is displayed throughout.

What I need is this:
When I click the caption in Scene 1, the text should appear in show_desc. When I go to another scene, there should be no text unless I click on the caption for that scene.

I’m not sure how to accomplish this, and I’ve been trying everything I could think of/could find with no success.

Thanks so much for your help!

EDIT:
Okay, so… I figured out that problem, sort of.

The caption is set as a button. It’s got an onRelease function, so when it is released, it displays the XML data.

I had a function wrapped around the first function, which delayed the XML-display function by one second.

It seems that, with that function added in, it was just continually asking for the XML data over and over and over again.

The thing is, I do need that delay to occur. What I was using before was:

function wait () {
[Function to call for XML Data]
}
myTimer = setInterval (wait, 1000);

Is there something that needs to be added so that it isn’t constantly asking for the XML data? Or some other way to delay the XML data from being displayed within the onRelease function?

Thanks again!

dont
use
scenes

Thanks for the sweet advice.

Do you have anything more substantial, like what I should be doing instead? Also, any ideas on the delay issue?

its probably because your attaching it with actionscript,

AS will attach stuff untill you tell it to go away

.visible . alpha

to be frank you will have to get rid of the scenes and timeline control

you will have to FOLLOW STANDARD PROTOCAL

and stick each page in an MC

once you have got your head round that and the coding involved you will figure out what is going wrong

because there is no point telling you how to code incorrectly.

Thanks for the reply, random.

How else do I go about attaching the XML data? I thought it was standard to attach it through Actionscript (I’m not sure of another way to do so).

So, let’s say I’ve got the placeholder where each image will load. It’s a movieclip called “graphics.” There is also the caption for each image, a button called “desc.”

There are five images in all for this slide show.

How do I go about setting each one up as a movieclip and calling them when the navigation calls for it?

Thanks for the help!

EDIT:

So, I decided to use a straight tutorial and go from there. So, I’m following this one right now:
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm

It basically does do what I need it to do, but I need to make one alteration and I’m not sure how to do so. How would I add navigation that allows you to go to each picture, rather than just going to the next and previous images?

I’d like to have buttons for image one, two, three, four and five.

When I create the button, how do I tell it to go to a specific image number rather than just ++ or --?

Thanks again for the help!

Hi,
What randomagain says is using best practices in Flash. So remember that and avoid scenes in future projects unless actionscripting is very minimalistic. There are times when scenes are required because flash has limited number of frames for very long movies so its basically project centric. All aside. Regarding your predicament.
Try shifting your code inside a function and call that function from your button

So this below would be
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“inventors.xml”);

=====================
function readXML()
{
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“inventors.xml”);
}

in your Button
on (release)
{
readXML();
}

In case your textfield doesnt clear up remember to put a mytextfield.text=""; as well

Wish you luck.

dont
use
AS
inside
symbols:)

have everything in 1 frame… i tell you. And i work with flash as a pro :slight_smile:

Exco,

Thanks for the advice. I’ll have to play around with that when I get home.

Any ideas on the delay thing I was trying to work with?

Macsy,

I don’t mean to sound rude or anything, but can you actually offer any advice? You just tell me what NOT to do without lending any type of constructive help.

For the record, all of my AS is in the first frame.

there are futher examples on the main page also in the forums a guy did a grid thumbnail gallery set up

you might be able to find it by searching my posts from my profile page

as for buttons which link to images

GOD THIS COMES UP FAR TOO OFTEN

takes deep breath

you call each button “but1”,“but2”

you then …

search my posts again, I’ve made this example 3 times in the last 2 days

random:

I do know how to create a button. I know how to, onPress/Release/RollOver/whatever function, go to a different frame/scene/play a movie clip/etc.

I just don’t know how to, on a button action, load a certain picture from the XML file.

I’ll check through your posts when I get home today, but just wanted to give you a heads up that I do know how to create a functional button here. Just unsure of how to create an action to load a different image called from the XML file.

would it confuse you more if when I say button I mean movieclip which acts like a button

xmlnode.childNodes[thisbuttonnumber]

I’m not really sure what you’re trying to say there…

Right now, I’m working right from that tutorial to get a more solid understanding of this. I’d say to work from that code with any sort of suggestions.

What would I add to that existing code so that when I press, say, “button2” it loads the second image from my XML file?

Thanks again, I really appreciate the help.

EDIT: Figured out the problem of fading in an image when the nav button is clicked. I thought I had tried it already, but who knows… tried so many other things, I may have overlooked it. Still unable to have an image appear when the first frame is loaded, though.

Alrighty, here we go. Scrapped everything and started new. Used an older gallery I had put together (with the help of… some tutorial somewhere. Maybe from here? Don’t remember.).

One scene. One frame. I’ve got it working almost as I want it to. There are a couple things that I can’t figure at the moment:

  • Load the first image in the XML file when the first frame loads

There are some tiny tweaks that I’d like to figure out, but they’re not totally important right now. Those two are the main things that I’m having trouble with.

Here is my code:

stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;

this.onLoad = function() {
    whitebox.gotoAndPlay(2);
    welcome.gotoAndPlay(1);
    var tranTween:Tween = new Tween(button, "_alpha", None.easeNone, 0, 100, 3, true);
};
myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = function(success) {
    numimages = this.firstChild.childNodes.length;
    spacing = 20;
    originalx = 0;
    originaly = 0;
    currentx = originalx;
    currenty = originaly;
    for (i=0; i<numimages; i++) {
        if ((i%11 == 0) && (i>0)) {
            currentx = originalx;
            currenty += 20;
        }
        this.picHolder = this.firstChild.childNodes*;
        this.thumbHolder = button.createEmptyMovieClip("thumbnail"+i, i);
        this.thumbHolder._x = currentx;
        this.thumbHolder._y = currenty;
        currentx += spacing;
        this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
        this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
        this.thumbHolder.desc = this.picHolder.attributes.desc;
        this.thumbHolder.title = this.picHolder.attributes.title;
        this.thumbHolder.main = this.picHolder.attributes.main;
        this.thumbHolder.onRelease = function() {
            var tranTween:Tween = new Tween(loader, "_alpha", None.easeNone, 0, 100, .75, true);
            welcome.gotoAndStop(1);
            loader.loadMovie(this.main);
            desc.text = this.desc;
            title.text = this.title;
        };
    }
};
myPhoto.load("images.xml");

if you want to load the first picture remove the for loop

or place 1 rather than numimages

ie <1 not <numimages

Hey random… tried both of those, but no dice. When I put a 1 in place of numimages, my navigation doesn’t show up.

When I remove the for loop completely, I get an “Error Opening Url” message in the output box.

ah right fine, I see

keep the loop as it was, however stick outside of the loop a container.loadMovie(xmlnode.childnodes[1])

it showed an error as I suspect you left the[“i”] incrementor even though you were removing the loop

I’m still getting nothing… not sure what the issue is. I’m going to post my code as it is now - would you be able to modify it with what I would need to make this happen? Maybe I’m just trying it in the wrong spots…

Thanks again for all of your help, random!

stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;

this.onLoad = function() {
    whitebox.gotoAndPlay(2);
    welcome.gotoAndPlay(1);
    var tranTween:Tween = new Tween(button, "_alpha", None.easeNone, 0, 100, 3, true);
};

function loadXML(loaded){
    if (loaded) {
    rootNode = myPhoto.firstChild;
    totalSlides = rootNode.childNodes.length;
    firstSlideNode = rootNode.firstChild;
    currentSlideNode = firstSlideNode;
    currentIndex = 1;
    updateSlide(firstSlideNode);
    numimages = this.firstChild.childNodes.length;
    spacing = 20;
    originalx = 0;
    originaly = 0;
    currentx = originalx;
    currenty = originaly;
    for (i=0; i<numimages; i++) {
        if ((i%11 == 0) && (i>0)) {
            currentx = originalx;
            currenty += 20;
        }
        this.picHolder = this.firstChild.childNodes*;
        this.thumbHolder = button.createEmptyMovieClip("thumbnail"+i, i);
        this.thumbHolder._x = currentx;
        this.thumbHolder._y = currenty;
        currentx += spacing;
        this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
        this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
        this.thumbHolder.desc = this.picHolder.attributes.desc;
        this.thumbHolder.title = this.picHolder.attributes.title;
        this.thumbHolder.main = this.picHolder.attributes.main;
        this.thumbHolder.onRelease = function() {
            var tranTween:Tween = new Tween(loader, "_alpha", None.easeNone, 0, 100, .75, true);
            welcome.gotoAndStop(1);
            loader.loadMovie(this.main);
            desc.text = this.desc;
            title.text = this.title;
        }
        };
    }
};
myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.onLoad = loadXML;
myPhoto.load("images.xml");

how does your xml file look?

Here’s the XML:

<gallery>
<image title="Show Title One" desc="Show One Description" main="1.jpg" thmb="button.jpg" />
<image title="Show Title Two" desc="Show Two Description" main="2.jpg" thmb="button.jpg" />
<image title="Show Title Three" desc="Show Three Description" main="3.jpg" thmb="button.jpg" />
<image title="Show Title Four" desc="Show Four Description" main="4.jpg" thmb="button.jpg" />
<image title="Show Title Five" desc="Show Five Description" main="5.jpg" thmb="button.jpg" />
</gallery>

Just wanted to see if anyone might have had any ideas crop up? Or maybe it’s just a slow weekend around these parts, heh.