views:

319

answers:

2

I am working on a Flash AS2 script that adds an instance of a movieclip for each node in an XML file. I have also included titles for each node in the XML file and I would like to display these when a user clicks on one of the individual movieclips. I have played around with clipevents and attachMovie but for the life of me I can't figure out how to approach this problem. Any ideas?

Ok Now with update script - yea!

var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("map.xml");
myXML.onLoad = function(success) {
if (success) {
var myPin = myXML.firstChild.childNodes;
for (i=0; i<myPin.length; i++) {

var pinNumber = i+1;

_root.attachMovie("box", "pin"+i, _root.getNextHighestDepth());
var xpos = Number(myPin[i].attributes["xpos"]);
var ypos = Number(myPin[i].attributes["ypos"]);
_root["pin" + i]._x = xpos;
_root["pin" + i]._y = ypos;
_root["pin" + i].popup.titleBox.text = myPin[i].firstChild.nodeValue;

_root["pin" + i].popup._visible = false;// hide the title to begin with
_root["pin" + i].onRelease = function () { //when the pin is clicked...
_root["pin" + i].popup._visible=!_root["pin" + i].popup._visible; //toggle the titleBox's visibility
}

}
}
};
A: 

Hi Thomas, welcome to SO.

You could try something like this (when creating each pin):

_root["pin" + i].titleBox._visible = false;// hide the title to begin with

_root["pin" + i].onRelease = function () { //when the pin is clicked...
this.titleBox._visible=!this.titleBox._visible; //toggle the titleBox's visibility
}

(EDIT: changed the onRelease function to use 'this.titleBox')

The details would depend on exactly how you want it to behave.

Hope this helps.

Richard Inglis
This makes a lot of sense. Its been so long since I worked with Flash, I totally forgot about visibility. Im still having some issues though - it seems that the textbox is hiding itself successfully and I traced the onRelease function, so I know that it is working properly. However its not making the textbox appearing. Grrr...
Thomas
I see you have titleBox.titleBox.text ... is this correct?
Richard Inglis
I saw that too, apparently I turned the dynamic text into a movieclip ages ago. I have replaced the symbol with a standard dynamic textbox and changed the code to titleBox.text - still no good.
Thomas
Must be a typo or dot missing somewhere - this should totally work...
Thomas
Does any of it work? are the pins being created correctly? try putting some trace statements in to check each step of the process.
Richard Inglis
Pins are creating correctly, text is invisible and the buttons are firing (tested it with trace()). The only thing that isn't happening is the dynamic text isn't becoming visible.
Thomas
Perhaps the value of titleBox.text is note being set correctly from the xml? Maybe try using a dummy value (eg "mytext") instead of myPin[i].firstChild.nodeValue; to see if that's where the problem is?
Richard Inglis
The text is getting set correctly - when I remove the line that sets it ot invisible, it shows up just fine. I tried setting it to static text but it didn't change anything either.
Thomas
Just to check, can you edit your question to include your updated code... in case there's a typo or something:)
Richard Inglis
Just updated the script.
Thomas
Ok try changing the last line to: this.popup._visible=!this.popup._visible;
Richard Inglis
Brrrrrrrrrrravo! It works. Just for the record, do you know why it works?
Thomas
Probably because by the time you click, the value of i has changed - you could test this by adding trace(i);
Richard Inglis
A: 

what is meant by Display Node in PLC Configuration

Devendran