Flash-XML help

  • elektric
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Mexico

Post 3+ Months Ago

Hello, I need some help here, I have this simple xml menu which is a list of items pulled from a xml file like this:

Code: [ Select ]
<lasvillas>
<villas>
<nombre>Diosa de la luna</nombre>
<link>1</link>
</villas>
<villas>
<nombre>Hacienda de Santa Rita</nombre>
<link>2</link>
</villas>
</lasvillas>
  1. <lasvillas>
  2. <villas>
  3. <nombre>Diosa de la luna</nombre>
  4. <link>1</link>
  5. </villas>
  6. <villas>
  7. <nombre>Hacienda de Santa Rita</nombre>
  8. <link>2</link>
  9. </villas>
  10. </lasvillas>


you will find a <link> value, instead of using this value as a link to another file, i need this to be a onPress to take the user to another frame on my timeline, ie. gotoAndPlay...

I imagine I need to create an empty movie clip per each group of values on my xml and give it an action, but How?


This is my current actionscript just in case you need it.
Code: [ Select ]
headlineXML = new XML();
headlineXML.onLoad = myLoad;
headlineXML.load("villasrsst.xml");

function myLoad(ok) {
    if (ok == true) {
        Publish(this.firstChild);
    }
}

function Publish(HeadlineXMLNode) {
    if (HeadlineXMLNode.nodeName.toUpperCase() == "LASVILLAS") {
        content = "";
        lasvillas = HeadlineXMLNode.firstChild;
        while (lasvillas != null) {
            if (lasvillas.nodeName.toUpperCase() == "VILLAS") {
                lead = "";
                mylink = "";
                element = lasvillas.firstChild;
                i = 30;
                while (element != null) {
                    if (element.nodeName.toUpperCase() == "NOMBRE") {
                        lead = element.firstChild.nodeValue;
                    }
                    if (element.nodeName.toUpperCase() == "LINK") {
                        mylink = element.firstChild.nodeValue;
                    }

                    element = element.nextSibling;
                }
                // Like HTML with link to external page
                //content += "<font size='+2' color='#3366cc'><a href='"+mylink+"'>"+lead+"</a></font><br><br>";
                
                // trying to build the same but whish to make this a button with a onPress like function.
                content += lead+"<br><br>";
                txt.htmltext=content;
            }
            lasvillas = lasvillas.nextSibling;
        }
    }
}
  1. headlineXML = new XML();
  2. headlineXML.onLoad = myLoad;
  3. headlineXML.load("villasrsst.xml");
  4. function myLoad(ok) {
  5.     if (ok == true) {
  6.         Publish(this.firstChild);
  7.     }
  8. }
  9. function Publish(HeadlineXMLNode) {
  10.     if (HeadlineXMLNode.nodeName.toUpperCase() == "LASVILLAS") {
  11.         content = "";
  12.         lasvillas = HeadlineXMLNode.firstChild;
  13.         while (lasvillas != null) {
  14.             if (lasvillas.nodeName.toUpperCase() == "VILLAS") {
  15.                 lead = "";
  16.                 mylink = "";
  17.                 element = lasvillas.firstChild;
  18.                 i = 30;
  19.                 while (element != null) {
  20.                     if (element.nodeName.toUpperCase() == "NOMBRE") {
  21.                         lead = element.firstChild.nodeValue;
  22.                     }
  23.                     if (element.nodeName.toUpperCase() == "LINK") {
  24.                         mylink = element.firstChild.nodeValue;
  25.                     }
  26.                     element = element.nextSibling;
  27.                 }
  28.                 // Like HTML with link to external page
  29.                 //content += "<font size='+2' color='#3366cc'><a href='"+mylink+"'>"+lead+"</a></font><br><br>";
  30.                 
  31.                 // trying to build the same but whish to make this a button with a onPress like function.
  32.                 content += lead+"<br><br>";
  33.                 txt.htmltext=content;
  34.             }
  35.             lasvillas = lasvillas.nextSibling;
  36.         }
  37.     }
  38. }


Thanks in advance.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

just create a new movie clip in your library (Ctrl+F8 ) and place inside it a dynamic text and call it's instance: dtext
Export the movie for actionscript (right click on it-> linkage-> linkage name -> name it "link")
Next, for each link read from xml file, attach the movie and set it's coordinates and it's text.
i.e.:
Code: [ Select ]
// create first a holder for the links:
this.createEmptyMovieClip("mcLinks", 100); // or any other depth or next highest depth
nLinkIndex = 0;
while (... read xml ...)
{
 ....
  mylink = element.firstChild.nodeValue;
  crtLink = mcLinks.attachMovie("link", "link"+nLinkIndex, nLinkIndex);
  crtLink._x = x; // set x and y according to your needs
  crtLink._y = y;
  crtLink.dtext.text = myLink;
  crtLink.dtext.autoSize = true;
  crtLink.onRelease = function()
  {
    // jump somewhere, function of the link, best to a frame with a name read from xml file
   // i.e.: _root.gotoAndPlay("frame_name");
  }
}
  1. // create first a holder for the links:
  2. this.createEmptyMovieClip("mcLinks", 100); // or any other depth or next highest depth
  3. nLinkIndex = 0;
  4. while (... read xml ...)
  5. {
  6.  ....
  7.   mylink = element.firstChild.nodeValue;
  8.   crtLink = mcLinks.attachMovie("link", "link"+nLinkIndex, nLinkIndex);
  9.   crtLink._x = x; // set x and y according to your needs
  10.   crtLink._y = y;
  11.   crtLink.dtext.text = myLink;
  12.   crtLink.dtext.autoSize = true;
  13.   crtLink.onRelease = function()
  14.   {
  15.     // jump somewhere, function of the link, best to a frame with a name read from xml file
  16.    // i.e.: _root.gotoAndPlay("frame_name");
  17.   }
  18. }

that's kind of all.
  • elektric
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Mexico

Post 3+ Months Ago

Cool, thanks I will try asap.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 14 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.