Forum Moderators: open

Message Too Old, No Replies

Assigning dynamic text from an array

Having problems with field path

         

catcherintherye51

11:26 pm on Jun 29, 2006 (gmt 0)

10+ Year Member



I have a script that places dots on a map via XML coordinates. The script below places a dot on the map and places the property name above the dot:

myVilla = new XML();
myVilla.ignoreWhite = true;
myVilla.onLoad = function(success) {
numimages = this.firstChild.childNodes[0].childNodes.length;
for (i=0; i<numimages; i++) {
this.picHolder = this.firstChild.childNodes[0].childNodes[i];
this.thumbHolder = image_tn.createEmptyMovieClip("thumbnail"+i, i);
this.thumbHolder._x = this.picHolder.attributes.cx;
this.thumbHolder._y = this.picHolder.attributes.cy;
this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
this.thumbLoader.attachMovie("Dot", "Dot"+i, this.getNextHighestDepth());
this.thumbLoader.createTextField ("nametext", i+10,-35,-30,100,20);
this.thumbLoader.nametext.text = this.picHolder.attributes.villaname;
};
};
myVilla.load("myxml.xml");

The XML file looks something like this:

<img cx="50" cy="50" villaname="Villa Taz"/>

Where cx and cy are the coordinates and villaname is...well... the villa name.

Now rather than have the villa names appear through "createTextField" I want them to appear in a dynamic text box so that when you rollover the dot the name appears above it in a white box.

What works: The dots and names appear correctly on the map, and the rollover action shows a pop-up white box above the dot.

What doesn't work: When I rollover the dot, the white box appears but the villa name that is supposed to be in the "villaname_dt" field (located on the Dot clip) says "undefined". I'm using:

villaname_dt.text = this.picHolder.attributes.villaname;

To make a long story short, what value do I assign to villaname_dt.text=? that pulls from the villaname XML data from the array?

THANKS!

adni18

4:40 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tested to make sure villaname_dt.text actually works after it's defined?

Try this, just for testing:

villaname_dt.text =
this.picHolder.attributes.villaname;
alert(villaname_dt.text);

If that gives you what you want it to be, then you're in luck!

If not, make sure villaname_dt is defined as an object. If it's not,

villaname_dt = new Object();
villaname_dt.text =
this.picHolder.attributes.villaname;
alert(villaname_dt.text);

and let me know the results. :)

catcherintherye51

5:21 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



Thanks!

(Instead of alert I used trace.)

I'm still getting "undefined" in the dynamic text box, and "undefined" in the trace. The name of the dynamic text box is "villaname_dt". If I put villaname_dt.text = "test" then "test" appears in the box, as it should.

The problem is trying to figure out what villaname_dt.test should equal. Well, it 'should' equal whatever villaname is in the XML file, but I'm not sure what the correct path should be.

The array gets the correct coordinates from the XML using this:
this.thumbHolder._x = this.picHolder.attributes.cx;
this.thumbHolder._y = this.picHolder.attributes.cy;

So I'm trying to get the villaname from the XML using this:
villaname_dt.text = this.picHolder.attributes.villaname;

But I'm thinking villaname_dt should = something with the specific array info so it knows exactly which villaname to use.

For more clarification, the main XML loop creates separate movies (Dot1, Dot2, Dot3, etc.) using the Dot movie. Within the Dot movie is the dynamic text box (villaname_dt).

I can get the names to write themselves directly to the map using createTextField, but instead of writing directly to the map I want them to appear in the dynamic text box villaname_dt.

Thanks for the help... Any other ideas on how to get this to work? I think the solution is all in using the correct path.

adni18

7:37 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ooooh, I didn't realize you were using ActionScript. AS has some noticable differences in scripting, and object functionality might be a bit different. I suggest posting in the Flash forum.

Sorry!