PDA

View Full Version : Loading XML data in ScrollPane


FunkyMonkey
09-15-2005, 09:51 AM
Hi Guys,

I keep having a problem with loading XML data into a ScrollPane.

Let me break it down:
I have a content clip which loads XML data (from an external source) in a container clip which is linked in my library. And this, the container clip, is loaded in a ScrollPane.

I have written a function that loads the XML and if that works, break down the result array in bits so i can use it to populate dynamic text boxes and a movieclip with a image. (I check to see if the XML is loaded by tracing the XML file, and that works).

The problem lies here; it does not break up the array and does not populate my dyn. txt boxes. Does not give me any errors, it just shows a blank ScrollPane.

This is the code:


xmlInfo = new XML();
xmlInfo.onLoad = xmlLada;
xmlInfo.load("");
xmlInfo.cacheBuster = new Date().getTime();
xmlInfo.load("http://localhost/feeder.php?bit=0");

// Exec. function when XML is loaded
function xmlLada(succes) {
if (succes) {
// If all works
trace(xmlInfo);
//
xmlNode = this.firstChild;

var xPos = 2.0;
var yPos = 2.0;

//For loop to fill container MC with Array data
for (i=0; i < xmlNode.childNodes.length; i++) {
//attach the container clip
mc = this.attachMovie("container", "new"+i, i, {_x:xPos, _y:yPos});

//increase the y postion each time
yPos += mc._height+5;

//add the information
caseID[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue; // Case ID
client[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue; // Client
product[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue; // Product
pictureRect[i] = xmlNode.childNodes[i].childNodes[9].firstChild.nodeValue; // Picture Rectangle

mc.caseID.text = caseID[i][0];
mc.client.text = client[i][1];
mc.product.text = product[i][2];
mc.picta_mc.loadMovie(pictureRect[i][9], this["new"+1].picta_mc);
trace(pictureRect);
}

} else {
// **** hits the fan

}
}


And the XML looks like this:


<xml version="1.0" encoding="UTF-8">
<case_id>1</case_id>
<client>Testing</client>
<product>A Product</product>
<description>This is a test with Case_ID 1</description>
<date>2005</date>
<url>http://www.nu.nl</url>
<videofile>/assets/video/case_nu.flv</videofile>
<picture_thumb>assets/img/case_nu_thumb.jpg</picture_thumb>
<picture_full>assets/img/case_nu_full.jpg</picture_full>
<picture_rect>assets/img/case_nu_rect.jpg</picture_rect>
</case>
</xml>



I did a test with a normal Array, loading data from there, and breaking it up exactly the same way (and same code) and that works fine. I see a nice ScollPane with all the text and images

Can somebody please help me with this ?? I've been trying for two days now and my head hurts...

(I can post the FLA if someone is interested)

Thanks, in advance for your help,

Sidney

Darkware
09-15-2005, 01:24 PM
Yeah, if you look in the Server Side section of this forum, you'll see my post about loading in mySQL variables via PHP. I had the EXACT same problem. The flaw lies in the fact that you're working inside a scrollpane. I had SO many problems while my code was inside the scrollpane. First of all, you need to make sure you're targeting the movieclip inside the scrollpane with tmp_mc because tmp_mc is the automatic instance name given to MC's inside scrollpanes. You need to have an instance name for the scrollpane as well which you can manually do. So it'll be _root.myscrollpane.tmp_mc.mydynamictextboxes.text = whatever;

If that doesn't work, try sticking your code on _root instead of inside the tmp_mc in the scrollpane and have it work from there. That's what I ended up having to do. I spent 4 days researching this problem and about 15 hours each day trying to figure it out. And that's not an exageration. I absolutely _had_ to figure this out because it was the only way to do what I wanted in the project I'm working on now.

FunkyMonkey
09-15-2005, 01:44 PM
Thats my problem exactly! I've been bustin my b*** for the past two days, and i've been working on it even when i got home from work. I need this to work, because this i the biggest part of the project.

I even posted on the Macromedia Forums and they didn't even know...

I'll try this and let you know if it is working, thanks for the help,

Cheers, Sidney

FunkyMonkey
09-15-2005, 02:18 PM
Btw: tmp_mc as dynamic generated MC library linkage? Or what exactly what do you mean? Can you be more specific? Or post some edited code

Darkware
09-15-2005, 02:28 PM
I wanted to target a dynamic text box inside an MC that was inside an MC that was on _root I would type _root.myMC1.myMC2.myDynamicBox.text = "whatever"; You give the instance names "myMC1" "myMC2" and "myDynamicBox" to the MC, the MC inside the first MC, and the Dynamic text box respectively. You assign the instance names in the properties box. Windows>Properties if you don't have it displayed.

Now when you have a ScrollPane, You can give it an instance name just like myMC1. When you click on the ScrollPane, you can select what movie clip will load into that scrollpane. That's where your linkage name comes in. You will need to have a linkage name for that movie to load into the scrollpane. You will type that linkage name into the scrollpane properties where it asks for what movie to load. The linkage name is _not_ the name you use when targeting the movie clip however. Unlike myMC2 that resides inside myMC1 in the previous example, the movie clip inside the scrollapne is given the instance name "tmp_mc" automatically. Hence, you get _root.myscrollpane.tmp_mc.myDynamicBox.text = "whatever";

I'm happy to answer any other questions you have.

FunkyMonkey
09-15-2005, 03:56 PM
Aaaaagh! No matter what i try, it keeps failing.
I'm tracing values to see whether the xml loads, it does, but i cannot load the content in to the ScrollPane.
Can you maybee have a look at the FLA File (http://www.funky-monkey.nl/bm/array_ScrollPanel.zip). I'll give you a PM for my email. Is that cool?

Thanks in advance,

Sidney

PS. In the zip file are 3 file; An XML file, and 2 FLA's, the one with out the _3 is the one that works and how it should be.

Darkware
09-15-2005, 04:05 PM
unfortunately, I have a lower version of flash than you, so I am unable to view the .fla. I'm trying to instal Flash8 but it keeps saying the file is corrupted. =(

FunkyMonkey
09-16-2005, 07:40 AM
Here is the file again in Flash MX: here (http://www.funky-monkey.nl/bm/array_ScrollPanelMX.zip)

Thanks for looking at it!

Darkware
09-16-2005, 10:13 AM
1) in the parameter for the scrollpane - the "content path" - you list "tmp_mc" as the movie clip to load into the scrollpane. Incorrect. You need to specify the linkage name of the movie clip which should be something different from "tmp_mc"
2) your linkage name for the movie is tmp_mc. Change it to something else. Do not use tmp_mc.
3) tmp_mc is ONLY to be used when you are targeting the path in actionscript. _root.myscrollpane.tmp_mc.dynamicbox.text and such
-
ok, so we have the scrollpane instance name. That's ok as far as I can see. We have the linkage name for the movieclip you want to load into the scrollpane. F11 to view your objects, rightclick the movieclip, select linkage, change the linkage name to "LINKAGEmc". We have the contentPath parameter for the scrollpane (viewable in the properties window when you select the scrollpane). You have it set to tmp_mc. Change it to "LINKAGEmc" because LINKAGEmc is the linkage name you gave to the movieclip in the library that you want to load into the scrollpane. You're tell the scrollpane: "load the movie clip that has this linkage name"

Another problem I see is that you have xmlInfo.onLoad = xmlLada then you call the function xmlLada(loaded). Now the problem with this is that you're expecting xmlLada to catch the onLoad thing. It won't do this. Why not? Because you set xmlInfo.onLoad = to xmlLada. NOT xmlLada = to xmlInfo.onLoad which is what it SHOULD be. Furthermore, if it doesn't work after you change all these things, try taking the "loaded" part out of the function. Why? Because I don't believe you need it. Why not? Because xmlLada will be = to onLoad after you change your code and onLoad will know that the content has been loaded all the way. Hence why they call it "onLoad"

You might try "success" in place of "loaded" however because I've seen that done before, but I dunno if it works. From my experience, such parameters aren't really needed.

Darkware
09-16-2005, 10:21 AM
and again, I will stress this more so you understand properly.. the linkage name you give to the movieclip is the same name you will type in the contentPath section of the scrollpane. They are one in the same. When you target movie clips to set dynamic text boxes = to text, you always specify the instance names of the movies. Like I said before, _root.myMC1.myMC2.dynamicbox.text = "blah"; myMC1 and 2 and dynamicbox are all instance names you type in for those objects. When you add a scrollpane into the situation however, things change. Instead of assigning what would be "myMC2" an instance name, the scrollpane automatically assigns its own instance name to that movie clip. You can't name it yourself because it's dynamically loaded into the scrollpane. So how do we target the dynamic text box if it's inside a movie that's inside a scrollpane? _root.myscrollpane.????.dynamicbox.text = "blah"; Since your movie clip is dynamically loaded into the scrollpane, the scrollpane gives it the instance name "tmp_mc". So like I said before, the only place you actually type tmp_mc is when you're typing the path. _root.myscrollpane.tmp_mc.dynamicbox.text

I hope this better explains things and clears up the confusion you're having.