dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [as3.0]

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Posts
    17

    [as3.0]

    Hi everybody

    I would like to change tag order in my xml file... based on the tag <order>
    for example I have xml file
    <?xml version="1.0" encoding="UTF-8"?>
    <list>
    <material>
    <title>Something 2</title>
    <order>2</order>
    </material>
    <material>
    <title>Something 3</title>
    <order>3</order>
    </material>
    <material>
    <title>Something 1</title>
    <order>1</order>
    </material>
    </list>
    and after some action script actions I would like to get something like this
    <?xml version="1.0" encoding="UTF-8"?>
    <list>
    <material>
    <title>Something 1</title>
    <order>1</order>
    </material>
    <material>
    <title>Something 2</title>
    <order>2</order>
    </material>
    <material>
    <title>Something 3</title>
    <order>3</order>
    </material>
    </list>
    anyone can help me???

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    var xml:XML = <list>
    <
    material>
    <
    title>Something 2</title>
    <
    order>2</order>
    </
    material
    <
    material>
    <
    title>Something 3</title>
    <
    order>3</order>
    </
    material
    <
    material>
    <
    title>Something 1</title>
    <
    order>1</order>
    </
    material
    </list>;

    var 
    arr:Array = [];
    for 
    each(var mat in xml.materialarr.push({node:mat,order:mat.order});
    arr.sortOn("order");

    var 
    newXML:XML = <list></list>;
    for(var 
    i:int=0;i<arr.length;i++) newXML.appendChild(arr[i].node);

    trace(newXML); 

  3. #3
    Junior Member
    Join Date
    Apr 2008
    Posts
    17
    thanks a lot... that was exacly what I was lookin' for
    and one more question how should I modify Your code to do something like that:

    when the order node is empty it should be placed at the end of queue... example
    <?xml version="1.0" encoding="UTF-8"?>
    <list>
    <material>
    <title>Something 3</title>
    <order>3</order>
    </material>
    <material>
    <title>Something empty</title>
    <order></order>
    </material>
    <material>
    <title>Something 2</title>
    <order>2</order>
    </material>
    </list>
    and the result should be
    <?xml version="1.0" encoding="UTF-8"?>
    <list>
    <material>
    <title>Something 2</title>
    <order>2</order>
    </material>
    <material>
    <title>Something 3</title>
    <order>3</order>
    </material>
    <material>
    <title>Something empty</title>
    <order></order>
    </material>
    </list>
    Last edited by s2472; 05-25-2009 at 03:57 AM.

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    change this:
    PHP Code:
    arr.push({node:mat,order:mat.order}); 
    to this:
    PHP Code:
    arr.push({node:mat,order:mat.order.toString()||Infinity}); 

  5. #5
    Junior Member
    Join Date
    Apr 2008
    Posts
    17
    thank You once again...

  6. #6
    ___________________
    Join Date
    May 2004
    Posts
    3,174

  7. #7
    Junior Member
    Join Date
    Apr 2008
    Posts
    17
    ok one more thing hopefully the last one...

    <?xml version="1.0" encoding="UTF-8"?>
    <list>
    <material>
    <title>Ewolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jaj</title>
    <order>10</order>
    </material>
    <material>
    <title>Eastwood za kamer</title>
    <order></order>
    </material>
    </list>
    if my title tag has above 40chars I would like to replace him into this tag first 40characters and then three dots... I have something like this I have almost everything but I don't know how two replace tag


    PHP Code:
    for each (var property:XML in newXML.material)
    {
        var 
    titleXML:String String(property.title);
        if (
    titleXML.length 40)
        {
            var 
    shortenTitleXML:String =  titleXML.substr(0,39);
            var 
    shortenTitleXMLDots:String shortenTitleXML "...";

            
    //and know the replacement

        
    }

    Last edited by s2472; 05-25-2009 at 04:02 PM.

  8. #8
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    for each (var property:XML in newXML.material

        var 
    titleXML:String String(property.title); 
        if (
    titleXML.length 40
        { 
            var 
    shortenTitleXML:String =  titleXML.substr(0,39); 
            var 
    shortenTitleXMLDots:String shortenTitleXML "..."

            
    // add this
           
    property.title shortenTitleXMLDots;
        } 


  9. #9
    Junior Member
    Join Date
    Apr 2008
    Posts
    17
    heh You're amazing...

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