A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Unload XML????

  1. #1
    Senior Member
    Join Date
    Nov 2006
    Posts
    162

    Unload XML????

    Hi,

    I am very new to XML, I built an image gallery, which contains several albums.
    I have each albums on a different frame of one MC.

    The xml code on each frame is this:


    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		image = [];
    		description = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		firstImage();
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("XML/images02.xml");
    // ///////////////////////////////////
    listen = new Object();
    listen.onKeyDown = function() {
    	if (Key.getCode() == Key.LEFT) {
    		prevImage();
    	} else if (Key.getCode() == Key.RIGHT) {
    		nextImage();
    	}
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    	prevImage();
    };
    next_btn.onRelease = function() {
    	nextImage();
    };
    // ///////////////////////////////////
    p = 0;
    this.onEnterFrame = function() {
    	filesize = picture.getBytesTotal();
    	loaded = picture.getBytesLoaded();
    	preloader._visible = true;
    	if (loaded != filesize) {
    		preloader.preload_bar._xscale = 100*loaded/filesize;
    	} else {
    		preloader._visible = false;
    		if (picture._alpha<100) {
    			picture._alpha += 10;
    		}
    	}
    };
    function nextImage() {
    	if (p<(total-1)) {
    		p++;
    		if (loaded == filesize) {
    			picture._alpha = 0;
    			picture.loadMovie(image[p], 1);
    			desc_txt.text = description[p];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		desc_txt.text = description[p];
    		picture_num();
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		desc_txt.text = description[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }

    It is working fine, except, when I change frame (albums), the XML stays the same as previous, it does not get uploaded.
    I assume I should do something like "unloading" the current XML to make room for the next?
    Am I right? How would I do it?

    Thanks!

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    flash loads the xml only inside its ram its not really openening the file like OS does with read/write permissions (wich would block other applications for example if they try to edit/read that file as well).

    It might be rather a browser thingy called cache , just hit ctrl+F5 (works in IE,FF and Opera) and it should reload the pages while clearing the cache. If that doesn´t work manually clear the cache. In firefox you can do that by hitting ctrl+shift+delete and check cache and enter ok.

    If still nothing improved check if you uploaded the correct xml file

  3. #3
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Thank you for your reply, I found my problem, and it was not related to the XML loading as you said, but an issue with my script.
    Thank you for your help.

  4. #4
    Junior Member
    Join Date
    Apr 2008
    Posts
    3
    Can you tell me how you solved your problem. Its seems i'm having the same issue. Thanks.

  5. #5
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Hi buddha16,

    My problem was actually an error in actionscript, which was not communicating correctly to the different XML. Yours could be lots of different things, if you can show me your code, I can give it a try.

  6. #6
    Junior Member
    Join Date
    Apr 2008
    Posts
    3
    Hi sandraa, Well my my issue is that i want two different galleries in my main movie but when you call one gallery and it loads the xml data and then when you go to the second it shows the loaded gallery instead of the second xml gallery. I was reading around as well and came across a idea maybe. If i put the galleries in their own movie and just call the swf's from my main..... Thanks for the help btw really appreciate it.

    Code:
    function initGallery()
    {
        function loadXML(loaded)
        {
            if (loaded)
            {
                xmlNode = this.firstChild;
                total = xmlNode.childNodes.length;
                for (i = 0; i < total; i++)
                {
                    _root.small_image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                    _root.big_image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                    _root.description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
                    if (i == 0)
                    {
                        _root.loadGImage(_root.description[i], _root.big_image[i]);
                    } // end if
                } // end of for
                createSmall();
                _root.downloadButton._visible = true;
            }
            else
            {
                content = "file not loaded!";
            } // end else if
        } // End of the function
        xmlData = new XML();
        xmlData.ignoreWhite = true;
        xmlData.onLoad = loadXML;
        if (_root.xml_file == undefined)
        {
            _root.xml_file = "paintings.xml";
        } // end if
        xmlData.load(xml_file);
    } // End of the function
    function createSmall()
    {
        _root.smallContainer.createEmptyMovieClip("smallImageContainer", 12);
        var _loc4 = 0;
        var _loc3 = 0;
        for (var _loc2 = 0; _loc2 < _root.small_image.length; ++_loc2)
        {
            _root.smallContainer.imageContainer.attachMovie("smallImage", "smallImage_" + _loc2, 100 + _loc2);
            m = _root.smallContainer.imageContainer["smallImage_" + _loc2];
            m._x = _loc3 * 50;
            m._y = 0;
            m.imageContainer.loadMovie(_root.small_image[_loc2], 100);
            m.iData = Array();
            m.iData.big = _root.big_image[_loc2];
            m.iData.title = _root.description[_loc2];
            ++_loc3;
        } // end of for
        _root.smallImageContainer._x = 5;
        _root.smallImageContainer._y = 0;
    } // End of the function
    function loadGImage(title, bigImgURL)
    {
        _root.bigImage.imageContainer.loadMovie(bigImgURL, 100);
        _root.bigImage.imageContainer._x = 0;
        _root.bigImage.imageContainer._y = 0;
        _root.title.text = title;
        _root.downloadButton.onRelease = function ()
        {
            getURL(bigImgURL, "_blank");
        };
    } // End of the function
    _root.description = new Array();
    _root.small_image = new Array();
    _root.big_image = new Array();
    initGallery();
    downloadButton._visible = false;

  7. #7
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Hi ,

    sorry for the late reply here..

    What about having 2 different XML files (paintingsone.xml, paintingstwo.xml)
    then, have your 2 galleries on two different frames in the same .swf and modify your code on each frame. You modify this line:
    _root.xml_file = "paintings.xml";

    does that make sens? this is how I got it working on mine.

  8. #8
    Junior Member
    Join Date
    Apr 2008
    Posts
    3
    Hi sandraa, thanks for the reply. I tried the way you said before but the issue that comes up is no matter which gallery is loaded first when you go back and try and load the second it displays the gallery loaded previously. Lol wow thats confusing. I wanted to find a way to unload the first gallery loaded and start fresh when the second was called. Thanks again.

  9. #9
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Hi Buddha16,

    this is how my gallery is set up, I have different albums, each on a different frame

    PHP Code:
    stop();

    function 
    loadXML(loaded) {
    if (
    loaded) {
    xmlNode this.firstChild;
    image = [];
    description = [];
    total xmlNode.childNodes.length;
    for (
    i=0i<totali++) {
    image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    }
    firstImage();
    } else {
    content "file not loaded!";
    }
    }
    xmlData = new XML();
    xmlData.ignoreWhite true;
    xmlData.onLoad loadXML;
    xmlData.load("galleryplanes.xml");
    /////////////////////////////////////
    listen = new Object();
    listen.onKeyDown = function() {
    if (
    Key.getCode() == Key.LEFT) {
    prevImage();
    } else if (
    Key.getCode() == Key.RIGHT) {
    nextImage();
    }
    };
    Key.addListener(listen);
    previous_btn.onRelease = function() {
    prevImage();
    };
    next_btn.onRelease = function() {
    nextImage();
    };
    /////////////////////////////////////
    0;
    this.onEnterFrame = function() {
    filesize picture.getBytesTotal();
    loaded picture.getBytesLoaded();
    preloader._visible true;
    if (
    loaded != filesize) {
    preloader.preload_bar._xscale 100*loaded/filesize;
    } else {
    preloader._visible false;
    if (
    picture._alpha<100) {
    picture._alpha += 10;
    }
    }
    };
    function 
    nextImage() {
    if (
    p<(total-1)) {
    p++;
    if (
    loaded == filesize) {
    picture._alpha 0;
    picture.loadMovie(image[p], 1);
    desc_txt.text description[p];
    picture_num();
    }
    }
    }
    function 
    prevImage() {
    if (
    p>0) {
    p--;
    picture._alpha 0;
    picture.loadMovie(image[p], 1);
    desc_txt.text description[p];
    picture_num();
    }
    }
    function 
    firstImage() {
    if (
    loaded == filesize) {
    picture._alpha 0;
    picture.loadMovie(image[0], 1);
    desc_txt.text description[0];
    picture_num();
    }
    }
    function 
    picture_num() {
    current_pos p+1;
    pos_txt.text current_pos+" / "+total;

    Then, a different XML file for each albums of the gallery,

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    send the xml name as a parameter to the function.
    use the function to load a new xml file and refresh the arrays.
    PHP Code:
    function Gallery(xml_file){

    description = new Array();
    small_image = new Array();
    big_image = new Array();

    if (
    xml_file == undefinedxml_file "paintings.xml";
    xmlData = new XML();
    xmlData.ignoreWhite true;
    xmlData.load(xml_file);

    xmlData.onLoad = function(){
    xmlNode this.firstChild;
    total xmlNode.childNodes.length;
    for (
    0totali++){
    small_image[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    big_image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
    if (
    == 0loadGImage(description[i],big_image[i]);
    }
    createSmall();
    }; 
    };

    Gallery("paintings.xml");

    // when you want to change the xml file
    // Gallery("etchings.xml"); 
    hth

  11. #11
    Member
    Join Date
    Dec 2007
    Posts
    37
    Did anyone find a solution to this? I'm having the same problem and have tried everything I can think of.

    My movie loads different galleries (each a different swf with a corresponding xml file -- say, gallery1.swf and gallery1.xml, etc.) Whichever gallery loads FIRST, that xml data carries over to any other gallery I click on.

    No amount of unloading movies seems to help.

    Here's the weird thing -- if I make a hidden button to FORCE a new gallery load, that works -- but only if the incorrect XML has already loaded. It makes no sense to me at all.

  12. #12
    Member
    Join Date
    Dec 2007
    Posts
    37
    Okay, here's what I did which, for some reason, works.

    You have to call the new swf twice.

    I know, it makes no sense. But for some reason, loading a movie with an xml just doesn't quite kick Flash into gear the first time. It uses the old xml data first, at the time it started displaying the movie. By then, it's too late.

    But, if, say, on frame 2, I have:

    loadMovie("firstgallery.swf",_root.mymovieclip);

    Then I also need, on frame 3:

    loadMovie("firstgallery.swf",_root.mymovieclip);

    I think the first time it's throwing the swf into mymovieclip but forgets to make sure the xml is new. If, a frame later, you call it again, it always works, 100% of the time.

    Again, no clue why. But try it.

  13. #13
    Junior Member
    Join Date
    Nov 2006
    Posts
    4
    Hi a_modified_dog,

    I know this post has been around a couple of years but I'm still having trouble replacing my xml file. I used your code which helped me out a lot but I still can't get rid of the old xml data. The new one loads but the old stays there. Any chance you can help me out?
    Thanks!!

    PHP Code:
    var spot_list:Array = [];

    function 
    Gallery(xml_file) {

        if (
    xml_file == undefined) {
            
    xml_file "xml/europe.xml";
        }
        
    xmlData = new XML();
        
    xmlData.ignoreWhite true;
        
    xmlData.load(xml_file);

        
    spot_list = new Array();

        
    xmlData.onLoad = function(load_status:Boolean):Void  {
            var 
    nodes:Array = this.firstChild.childNodes;
            
    // Get Nodes Length
            
    spot_list_length nodes.length;
            
    // read all XML data  
            
    for (var 0i<nodes.lengthi++) {
                
    // add all spot information to spotlist array 
                
    spot_list.push({location_name:nodes[i].attributes.location_namex:nodes[i].attributes.xy:nodes[i].attributes.yurl:nodes[i].attributes.urlswf:nodes[i].attributes.swf});
            }
            
    // call duplicate spot function 
            
    create_spot_list();
        };
    }
    Gallery("xml/europe.xml");

    bt_france.onPress = function() {
        
    Gallery("xml/spots.xml");
    }; 

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try removing the xml decleration from outside of the function -
    var spot_list:Array = [];

    from Test Movie, use List Variables to see how xmlData and spot_list are compiled
    when new data is loaded

  15. #15
    Junior Member
    Join Date
    Nov 2006
    Posts
    4
    Thanks so much for replying so rapidly.

    I get this when I List Variables:

    Clip: Cible="_level0.map_mc.spot_mc0"
    Variable _level0.map_mc.spot_mc0.location_name = "Paris/ France"
    Variable _level0.map_mc.spot_mc0.url =
    Variable _level0.map_mc.spot_mc0.swf_file = "external_swf/istanbul.swf"
    Variable _level0.map_mc.spot_mc0.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc0.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc0.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc1"
    Variable _level0.map_mc.spot_mc1.location_name = "Bruxelles / Belgique"
    Variable _level0.map_mc.spot_mc1.url =
    Variable _level0.map_mc.spot_mc1.swf_file = "external_swf/new_york.swf"
    Variable _level0.map_mc.spot_mc1.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc1.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc1.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc2"
    Variable _level0.map_mc.spot_mc2.location_name = "Toulouse / France"
    Variable _level0.map_mc.spot_mc2.url =
    Variable _level0.map_mc.spot_mc2.swf_file = "external_swf/sydney.swf"
    Variable _level0.map_mc.spot_mc2.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc2.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc2.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc0"
    Variable _level0.map_mc.spot_mc0.location_name = "Istanbul / Turkey"
    Variable _level0.map_mc.spot_mc0.url =
    Variable _level0.map_mc.spot_mc0.swf_file = "external_swf/istanbul.swf"
    Variable _level0.map_mc.spot_mc0.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc0.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc0.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc1"
    Variable _level0.map_mc.spot_mc1.location_name = "New York / United States"
    Variable _level0.map_mc.spot_mc1.url =
    Variable _level0.map_mc.spot_mc1.swf_file = "external_swf/new_york.swf"
    Variable _level0.map_mc.spot_mc1.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc1.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc1.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc2"
    Variable _level0.map_mc.spot_mc2.location_name = "Sydney / Australia"
    Variable _level0.map_mc.spot_mc2.url =
    Variable _level0.map_mc.spot_mc2.swf_file = "external_swf/sydney.swf"
    Variable _level0.map_mc.spot_mc2.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc2.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc2.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc3"
    Variable _level0.map_mc.spot_mc3.location_name = "Buenos Aires / Argentina"
    Variable _level0.map_mc.spot_mc3.url =
    Variable _level0.map_mc.spot_mc3.swf_file = "external_swf/buenos_aires.swf"
    Variable _level0.map_mc.spot_mc3.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc3.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc3.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc4"
    Variable _level0.map_mc.spot_mc4.location_name = "London / England"
    Variable _level0.map_mc.spot_mc4.url =
    Variable _level0.map_mc.spot_mc4.swf_file = "external_swf/london.swf"
    Variable _level0.map_mc.spot_mc4.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc4.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc4.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.map_mc.spot_mc5"
    Variable _level0.map_mc.spot_mc5.location_name = "Moscow / Russia"
    Variable _level0.map_mc.spot_mc5.url =
    Variable _level0.map_mc.spot_mc5.swf_file = "external_swf/moscow.swf"
    Variable _level0.map_mc.spot_mc5.onRollOver = [fonction 'onRollOver']
    Variable _level0.map_mc.spot_mc5.onRollOut = [fonction 'onRollOut']
    Variable _level0.map_mc.spot_mc5.onRelease = [fonction 'onRelease']
    Clip: Cible="_level0.__tweenLite_mc"
    Variable _level0.__tweenLite_mc.onEnterFrame = [fonction 'onEnterFrame']

    Basically it creates some little spots on a map, what I need to do is delete the first lot of spots that were created by the first XML... mc0, mc1 and mc2...and just leave the new ones. Do I have to clear out at _level0 before loading new or something like that??

    I really appreciate your help!

  16. #16
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to clear the spots - _level0.map_mc.spot_mc0 and so on, use a loop -

    PHP Code:
    for(var n=0;n!=100;n++){
    _level0.map_mc["spot_mc"+n].swapDepths(100); // needed for manual placement
    _level0.map_mc["spot_mc"+n].removeMovieClip(); 


  17. #17
    Junior Member
    Join Date
    Nov 2006
    Posts
    4

    resolved

    GREAT! Thanks!!....was trying loads of different codes to get that...but I lack too much AS language.
    Wish there were more 'modified_dogs' around....

    Thanks again!

  18. #18
    Junior Member
    Join Date
    Mar 2010
    Location
    Philippines
    Posts
    22
    Hi have this xml file consists of images i want to unload those images from my xml file when my swf file loads on the same stage. how do i do that i already use removeChild and unload() but it seems not working.still the was in my stage

    thanks

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