help please, having trouble with dynamic movieclips

  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

I am trying to build a site that can be populated by a series of child nodes in an xml file. I think i have everything down but one part. The childnodes populate an array in flash, but I want the childnodes(and their data) to populate a movie clip (for each one) and dynamically list these movie clips and their data on the stage (using x and y coordinates not into something like a scroll pane). I think what i need to do is create the movielclip and set its linkage in the library , but i am not sure how to implement it or get it to work with the array of child nodes. I have been finding pieces to this puzzle but its kind of hard to put it together. I am going to list below links to the tutorials that I found the pieces at. I thought it would be easier than pasting all the code in here. Ay help would be much appreciated. I am new to this forum, so hello ozzu community.

this one parses the xml data and populates an array with the child nodes
http://broadcast.artificialcolors.com/index.php?p=160&more=1&page=1

this is about attaching movie clip from the library
http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001487.html
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • CE/ Pyrocy
  • Proficient
  • Proficient
  • User avatar
  • Posts: 374
  • Loc: Santa Barbara, CA

Post 3+ Months Ago

just wondering are you trying to make a carousel using an external xml file to load in the objects?
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

No, I am just trying to make a list of movie clips.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

something like this ... where myMC is a movieclip in the library, exported as "myMC" in the first frame
Code: [ Select ]
// Create new XML Object and set ignoreWhite true
book_xml = new XML();
book_xml.ignoreWhite = true;
// Setup load handler which just invokes another function
// which will do the parsing of our XML
book_xml.onLoad = function(sucess) {
    if (sucess) {
        processBook(book_xml);
    }
};
// Load up the XML file into Flash
book_xml.load('book.xml');

// This is the function that will be called when
// our XML document is loaded succesfully
function processBook(xmlDoc_xml)
{
    var iIndex = 0;
    for (iNodeIndex in xmlDoc_xml.firstChild.childNodes)
    {
        var crtNode = xmlDoc_xml.firstChild.childNodes[iNodeIndex];
        trace(xmlDoc_xml.firstChild.childNodes[iNodeIndex].nodeName);
        var crtMC = this.attachMovie("myMC", "myMC" + iIndex, iIndex);
        for (iSubNodeIndex in crtNode.childNodes)
        {
            trace(crtNode.childNodes[iSubNodeIndex].nodeName);
            trace(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue);
            switch (Number(iSubNodeIndex))
            {
                case 0: crtMC._x = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
                case 1: crtMC._y = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
                case 2: crtMC._width = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
                case 3: crtMC._height = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
                case 4: crtMC._alpha = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
            }
        }
        iIndex ++;
    }
}
  1. // Create new XML Object and set ignoreWhite true
  2. book_xml = new XML();
  3. book_xml.ignoreWhite = true;
  4. // Setup load handler which just invokes another function
  5. // which will do the parsing of our XML
  6. book_xml.onLoad = function(sucess) {
  7.     if (sucess) {
  8.         processBook(book_xml);
  9.     }
  10. };
  11. // Load up the XML file into Flash
  12. book_xml.load('book.xml');
  13. // This is the function that will be called when
  14. // our XML document is loaded succesfully
  15. function processBook(xmlDoc_xml)
  16. {
  17.     var iIndex = 0;
  18.     for (iNodeIndex in xmlDoc_xml.firstChild.childNodes)
  19.     {
  20.         var crtNode = xmlDoc_xml.firstChild.childNodes[iNodeIndex];
  21.         trace(xmlDoc_xml.firstChild.childNodes[iNodeIndex].nodeName);
  22.         var crtMC = this.attachMovie("myMC", "myMC" + iIndex, iIndex);
  23.         for (iSubNodeIndex in crtNode.childNodes)
  24.         {
  25.             trace(crtNode.childNodes[iSubNodeIndex].nodeName);
  26.             trace(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue);
  27.             switch (Number(iSubNodeIndex))
  28.             {
  29.                 case 0: crtMC._x = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
  30.                 case 1: crtMC._y = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
  31.                 case 2: crtMC._width = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
  32.                 case 3: crtMC._height = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
  33.                 case 4: crtMC._alpha = parseInt(crtNode.childNodes[iSubNodeIndex].firstChild.nodeValue, 10); break;
  34.             }
  35.         }
  36.         iIndex ++;
  37.     }
  38. }


the content for the xml file that u need (book.xml):
Code: [ Select ]
<MovieClips>

   <MovieClip>
     <x>10</x>
     <y>20</y>
     <width>10</width>
     <height>20</height>
     <alpha>50</alpha>
   </MovieClip>

   <MovieClip>
     <x>50</x>
     <y>20</y>
     <width>50</width>
     <height>30</height>
     <alpha>70</alpha>
   </MovieClip>

   <MovieClip>
     <x>100</x>
     <y>150</y>
     <width>30</width>
     <height>20</height>
     <alpha>90</alpha>
   </MovieClip>

</MovieClips>
  1. <MovieClips>
  2.    <MovieClip>
  3.      <x>10</x>
  4.      <y>20</y>
  5.      <width>10</width>
  6.      <height>20</height>
  7.      <alpha>50</alpha>
  8.    </MovieClip>
  9.    <MovieClip>
  10.      <x>50</x>
  11.      <y>20</y>
  12.      <width>50</width>
  13.      <height>30</height>
  14.      <alpha>70</alpha>
  15.    </MovieClip>
  16.    <MovieClip>
  17.      <x>100</x>
  18.      <y>150</y>
  19.      <width>30</width>
  20.      <height>20</height>
  21.      <alpha>90</alpha>
  22.    </MovieClip>
  23. </MovieClips>
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

Thanks IceCold. That looks like its pretty much exactly what I want. Once I shake this cold I have I am gonna start working that in.

You Rock!

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 7 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.