View Full Version : Making List Component Items Clickable
notaflasher
07-04-2007, 08:55 PM
Using php & mysql to populate a simple list component in flash. The following code works to populate the list component.
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
I want to make the items clickable. I'm trying variations of the following code (that obviously doesn't work).
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
htext.htmlText = "<a href=\"http://www.anything.com\">nodes[i].firstChild.nodeValue</a>";
theList.addItem(htext,i);
}
}
I also want to be able to use asfunction to execute flash actions here as well, so maybe keep that in mind as well. Any help would be greatly appreciated.
LOLFlash
07-05-2007, 01:53 AM
I want to make the items clickable. I'm trying variations of the following code (that obviously doesn't work).
any Item in list is clickable. more over it is object with label and data properties by default. label what you can see on screen and data is behind the scene.
you can add flash listener to list component with respond function name
event "change" more usefull
inside function body you can call JavaScript or AS
is it what you want?
notaflasher
07-05-2007, 07:32 AM
I guess that "anything" is clickable if you really think about it. But if you click on something and nothing happens, then what's the point?
If you look at the second snippet of code, you will see what I want to do. No, the syntax isn't correct, but it's pretty obvious what I'm trying to accomplish.
I want each node to do "something" when clicked on. One might open an html page, another might load a .swf. All I want right now is help with the code to make all of them do the same thing. I just want to test my .swf and click on the items that show up in the list and then have an html page come up.
I don't know how else to explain it.
LOLFlash
07-05-2007, 03:40 PM
I just want to test my .swf and click on the items that show up in the list and then have an html page come up.
add this code:
function theListChange(evt:Object){
trace(evt.target.selectedItem.data);
}
theList.addEventListener("change",theListChange);
theXML.onLoad = function() {
var nodes:XMLNode = this.firstChild.childNodes;
var ln:Number = nodes.length;
for(i=0;i<ln;i++) {
theList.addItem({label:nodes[i].firstChild.nodeValue,data:nodes[i].firstChild.nextSibling});
}
}
I dont know your XML sructure if you search this forum in Components I posted example for list with XML not long time ago.
I like xml for list:
<items>
<item label="label Name1" data="data value2"/>
<item label="label Name2" data="data value2"/>
</items>
in AS you can go:
theList.dataProvider = this.firstChild;
in listener:
trace(evt.target.selectedItem.attributes.data);
List works directly with XML object
notaflasher
07-05-2007, 04:15 PM
LOLFlash,
Thanks for your help so far. I don't understand what your code does, unfortunately. I can't see how it would make the list items open up a web page since there is no URL specified anywhere.
I decided to try something different and replaced the component with a dynamic text box.
var titleXML:XML = new XML();
titleXML.ignoreWhite = true;
var sURL:String = "http://www.someurl.com";
titleXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.htmlText += "<a href=\"" + sURL + "\">" + nodes[i].firstChild.nodeValue + "</a>" + "\r\r";
}
}
titleXML.load("titles.php");
This works. And I dropped the UIScrollBar component onto the text box.
Here is the php file so you can see what I'm doing.
<?PHP
$link = mysql_connect("**mysqlserver**", "**username**", "password");
mysql_select_db ("database");
$query = 'SELECT * FROM entry';
$results = mysql_query($query);
echo "<?xml version=\"1.0\"?>\n";
echo "<entry>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["title"] . "</item>\n";
}
echo "</entry>\n";
mysql_close($link);
?>
That returns the following xml to flash...
<?xml version="1.0" ?>
<entry>
<item></item>
</entry>
Is there a reason for me to use the list component over the dynamic text box?
LOLFlash
07-05-2007, 04:34 PM
function theListChange(evt:Object){
getUrl(evt.target.selectedItem.attributes.data);
}
theList.addEventListener("change",theListChange);
theXML.onLoad = function(success) {
if(success) theList.dataProvider = this.firstChild;
}
$myoutput='<?xml version="1.0"?>"<entry>';
$mysite = 'http://mysite.com';
while($line = mysql_fetch_assoc($results)) {
$myoutput.='<item label =" '. $line['title'] .' " data =" '.$mysite.$line['title'].' " />';
}
$myoutput .= "</entry>";
echo $myoutput;
test your php first
it shuld give you formated XML in IE
<entry>
<item label="label" data = "thedata"/>
<item label="label" data = "thedata"/>
<item label="label" data = "thedata"/>
</entry>
but if you want render List as html text it is different question!!!!!
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.