dcsimg
A Flash Developer Resource Site

Page 3 of 3 FirstFirst 123
Results 41 to 50 of 50

Thread: using XML and movieClips/Objects?

  1. #41
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    oh..here is the code in its current/final revision so far:

    code:

    import mx.utils.Delegate;
    //
    //
    //
    var mc:MovieClip = this;
    var rootNode:XMLNode;
    var productsNode:Array;
    var totalProducts:Number;
    var myXML_xml = new XML();
    //
    myXML_xml.ignoreWhite = true;
    myXML_xml.onLoad = Delegate.create(this, getTotalProducts);
    myXML_xml.load("products.xml");
    //
    //
    //
    function getTotalProducts(success):Void {
    if (success == true) {
    rootNode = myXML_xml.firstChild;
    productsNode = rootNode.childNodes;
    totalProducts = rootNode.childNodes.length;
    createTemplates();
    this.onEnterFrame = Delegate.create(this, function() {
    populateAll();
    delete this.onEnterFrame;
    }
    ); //end Delegate
    } else {
    trace("Load Failed");
    }
    }
    function createTemplates():Void
    {
    for (i = 0; i < totalProducts; i++) {
    var attachProduct:MovieClip = attachMovie("templateClip", "product" + i, i);
    attachProduct._x += i * 220;
    attachProduct._y += 40;
    }
    }
    function populateAll():Void {
    for (i = 0; i < totalProducts; i++) {
    var totalSizes:String =productsNode[i].childNodes[3].childNodes.length;
    var totalColors:String =productsNode[i].childNodes[4].childNodes.length;
    trace("product"+i+" totalSizes: "+totalSizes);
    trace("product"+i+" totalColors: "+totalColors);
    //name
    var prodName:String = productsNode[i].childNodes[1].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.name_txt.text = prodName;
    trace("Name: "+prodName);
    //image
    var prodImage:String = productsNode[i].childNodes[0].firstChild.nodeValue;
    var obj4 = this["product" + i];
    obj4.prodImage_container.loadMovie("clothing/"+prodImage);
    trace("Image: "+prodImage);
    //price
    var prodPrice:String = productsNode[i].childNodes[2].firstChild.nodeValue;
    var obj2 = this["product" + i];
    obj2.price_txt.text = prodPrice;
    trace("Price: "+prodPrice);
    //description
    var prodDesc:String = productsNode[i].childNodes[5].firstChild.nodeValue;
    var obj3 = this["product" + i];
    obj3.desc_txt.text = prodDesc;
    trace("Description: "+prodDesc+newline);
    //sizes
    for (x = 0; x < totalSizes; x++) {
    var size:String = productsNode[i].childNodes[3].childNodes[x].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.sizeCombo.addItem(size);
    }
    //color
    for (y = 0; y < totalColors; y++) {
    var color:String = productsNode[i].childNodes[4].childNodes[y].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.colorCombo.addItem(color);
    }
    }
    }


  2. #42
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    a big "THANKS" to you indivision.

    You didnt abandon my thread.."AND"...you taught me alot throughout this whole time.

    Just wanted to say I appreciated it.

  3. #43
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    thanks for the thanks.

    let me know if i can help with anything else.

    btw- the code above looks vastly improved over the previous code.

  4. #44
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    thanks....here is the REAL (final) snippet: (withyour help of course)

    code:
    import mx.utils.Delegate;
    //
    //
    //
    var mc:MovieClip = this;
    var rootNode:XMLNode;
    var productsNode:Array;
    var totalProducts:Number;
    var myXML_xml = new XML();
    //
    myXML_xml.ignoreWhite = true;
    myXML_xml.onLoad = Delegate.create(this, getTotalProducts);
    myXML_xml.load("products.xml");
    //
    //
    //
    function getTotalProducts(success):Void {
    if (success == true) {
    rootNode = myXML_xml.firstChild;
    productsNode = rootNode.childNodes;
    totalProducts = rootNode.childNodes.length;
    createTemplates();
    this.onEnterFrame = Delegate.create(this, function() {
    populateAll();
    delete this.onEnterFrame;
    }
    ); //end Delegate
    } else {
    trace("Load Failed");
    }
    }
    function createTemplates():Void
    {
    for (i = 0; i < totalProducts; i++) {
    var attachProduct:MovieClip = attachMovie("templateClip", "product" + i, i);
    attachProduct._x += i * 220;
    attachProduct._y += 40;
    }
    }
    function populateAll():Void {
    for (i = 0; i < totalProducts; i++) {
    var totalSizes:String =productsNode[i].childNodes[3].childNodes.length;
    var totalColors:String =productsNode[i].childNodes[4].childNodes.length;
    trace("product"+i+" totalSizes: "+totalSizes);
    trace("product"+i+" totalColors: "+totalColors);
    //name
    var prodName:String = productsNode[i].childNodes[1].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.name_txt.text = prodName;
    trace("Name: "+prodName);
    //image
    var prodImage:String = productsNode[i].childNodes[0].firstChild.nodeValue;
    var prodLink:String = productsNode[i].childNodes[6].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.prodImage_container.innerContainer_mc.loadMovi e("clothing/"+prodImage);
    obj.linkVar = prodLink;
    trace("Image: "+prodImage);
    trace("URL: "+prodLink);
    //price
    var prodPrice:String = productsNode[i].childNodes[2].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.price_txt.text = prodPrice;
    trace("Price: "+prodPrice);
    //description
    var prodDesc:String = productsNode[i].childNodes[5].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.desc_txt.text = prodDesc;
    trace("Description: "+prodDesc+newline);
    //sizes
    for (x = 0; x < totalSizes; x++) {
    var size:String = productsNode[i].childNodes[3].childNodes[x].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.sizeCombo.addItem(size);
    }
    //color
    for (y = 0; y < totalColors; y++) {
    var color:String = productsNode[i].childNodes[4].childNodes[y].firstChild.nodeValue;
    var obj = this["product" + i];
    obj.colorCombo.addItem(color);
    }
    }
    }




    next datagrids I think..see what they're all about...(are they like a repeater panel of sorts???)

  5. #45
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok...I spoke to soon.. I guess I do need more help another question if you will.

    I am NOT a component fan..however..I will use one in this case.. if need be.

    future thinking here...if I want to be able to "contain" this code (portable)...what would I do? right now the test attaches all clips to _root..... I need to eventually move this a container of some sorts..so I cna scroll through it.

    So I was thinking of the scrollPane possibly? (ever use it) but Im not sure how that would even work..LOL...

    somehow run the code INSIDE the scrollPane? to attachClips..and then populate?

    Final solution..id liek to be able to have this .swf nothing more than a bunch of products...that can be scrolled through (preferabel vertically with a scrollbar)

    sugestions on a direction I should look into?

  6. #46
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    ok..I posted here with a .zip attachment...

    I think I am having another instatiate problem... where the XML products are being attached fast enough or BEFORE the variabel for the length of the scrollBar is being set. (if that makes sense).. anyways..located here if you are bored.

    http://www.flashkit.com/board/showth...87#post3593987

    you'll have to delete the textField and the yellowBG fill (to empty the clip) to duplicate the problem..if there IS somethign in the clip at authoring time..it will use that as the length....where as I need the clip to populate first..then set variables...

    I had tried all dfferent ways too.. my head is MUSH now...

  7. #47
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    hey. sorry i cant help more at the moment. im trying to meet a client deadline and am leaving town for a week tomorrow. maybe i can help more when i get back if you dont figure it out by then. good luck!

  8. #48
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    hey, no poblem at all. Dont feel obligated, you have helped plenty.. Im stoked that I know how to use XML in a practical way... (this is really a flahs issue).. I hav read an XML book before...and "understood" what XML was..and how to make my own hierarchy..but schemas and stuff that like always confused me, so I never put it to any use before...

    I quite like the regular XML parsing of XML..just one big multi-dimensional array.
    (mext next step is to make OUTPUT to XML with Flash & PHP, with an upload button for images..should be good practice with some of the new features in F8)
    I have posted here about it over the past two days..and to several threads...nada.

    So I might just be waiting for ya...LOL Have fun on your trip.

  9. #49
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    oh yeah. about the parsing. one more thing before i jump on a plane:

    now that you have a good understanding of how it works on the flash parser level. here's my parser. it might make you ask, "why didn't you just send this to begin with?!"

    mess around with it and i think you will understand the advantage. i will explain more when i get back if needed.

  10. #50
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    how about a quick note on it? LOL

    I man how much different can a parser be? you can make your own "custom" parser?

    Dont they all just import the data as an ARRAY? How does XPATH work?

    I'll check out your file right now...thanks.


    not to mention i see you are using external.as & classes..I have never done EITHER...so that already confuses me...LOL

    nice..I see you just access it by dot (.) syntax by node name? is that what your parser does?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center