A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Why AS variables only working on reload?

  1. #1

    Why AS variables only working on reload?

    So I'm trying to fix the site at http://intljewelry.com/index1.html - what's happening is that when you first visit the site, several of the areas with information that is loaded from an XML file are not showing up. However if you reload the page, they show up just fine. I'm guessing this is something in the order of functions in my AS, but as somebody else wrote the original code I can't figure it out.

    Here is the current code:


    Code:
    var mainXMLObj:XML = new XML();
    var collXMLObj:XML = new XML();
    mainXMLObj.ignoreWhite = true;
    collXMLObj.ignoreWhite = true;
    _global.mainDataArr = new Array();
    _global.collDataArr = new Array();
    mainHolder.loadMovie("book.swf");
    display_mc.loadMovie("display.swf");
    this.backgroundFrame.innerFrame.chickHolder.loadMovie("chicks.swf");
    
    parseMainXML = function(bSuccess:Boolean) {
                    if (bSuccess = true) {
                                    var lngth = mainXMLObj.firstChild.childNodes.length;
                                    for (i = 0; i < lngth; i++) {
                                                    var dataHold = new Object;
                                                    dataHold.attributes = mainXMLObj.firstChild.firstChild.attributes
                                                    dataHold.name = mainXMLObj.firstChild.firstChild.firstChild.childNodes[0].nodeValue;
                                                    dataHold.path = mainXMLObj.firstChild.firstChild.childNodes[1].firstChild.nodeValue;
                                                    dataHold.description = mainXMLObj.firstChild.firstChild.childNodes[2].firstChild.nodeValue;
                                                    mainDataArr[i] = dataHold;
                                                    mainXMLObj.firstChild.firstChild.removeNode();
                                                    dataHold = null;
                                    }
                                    delete mainXMLObj;
                                    mcholder._alpha = 0;
                                    mcholder.loadMovie(mainDataArr[0].attributes.URL + "/" + "scroller.swf");
                                    _global.clrInt = setInterval(fadeIn, 10);
                                    butt_hold.loadMovie("buttonSet.swf");
                    }
                    else {
                                    
                    }
    }
    
    parseCollXML = function(bSuccess:Boolean) {
                    if (bSuccess = true) {
                                    var lngth = collXMLObj.firstChild.childNodes.length;
                                    for (i = 0; i < lngth; i++) {
                                                    var dataHold = new Object;
                                                    dataHold.collName = collXMLObj.firstChild.childNodes[i].attributes.collName;
                                                    dataHold.collMain = collXMLObj.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
                                                    dataHold.collThumbs = collXMLObj.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
                                                    dataHold.collPrice = collXMLObj.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
                                                    dataHold.collSalePrice = collXMLObj.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue;
                                                    dataHold.collDescription = collXMLObj.firstChild.childNodes[i].childNodes[4].firstChild.nodeValue;
                                                    dataHold.collInventory = collXMLObj.firstChild.childNodes[i].childNodes[5].firstChild.nodeValue;
                                                    collDataArr[i] = dataHold;
                                                    mainXMLObj.firstChild.firstChild.removeNode();
                                                    dataHold = null;
                                    }
                                    delete mainXMLObj;
                    }
                    else {
                                    
                    }
    }
    
    mainXMLObj.onLoad = parseMainXML;
    collXMLObj.onLoad = parseCollXML;
    _global.siteIndex = 0;
    text1_mc.myText.autoSize = true;
    
    mainXMLObj.load("mainSiteData.xml");
    collXMLObj.load("siteCollection.xml");
    
    
    var cssSheet = new TextField.StyleSheet();
    cssSheet.load("Styles.css");
    text1_mc.myText.styleSheet = cssSheet;
    
    function LoadFunct() {
                    var lod = _root.mainHolder.getBytesLoaded();
                    var tot = _root.mainHolder.getBytesTotal();
                    var percent = lod/tot;
                    _root.mainHolder.progressBar.gotoAndStop(percent);
                    if (percent == 1) {
                                    delete this.onEnterFrame;
                                    removeMovieClip(_root.mainHolder.progressBar);
                    }              
    }
    
    _global.loadFile = function(oEvent:MovieClip, mov:String) {
                    mainHolder.attachMovie("progressBar", "progressBar", mainHolder.getNextHighestDepth(), {_x:50, _y:50});
                    mainHolder.loadMovie(mov);
                    mainHolder.picture.front.holder.loadMovie(mov);
                    mainHolder.buyNow.front.holder.smallPictHold.loadMovie(mov);
    };
    
    stop();
    You can also download the working files here: http://www.intljewelry.com/IJC_Working.zip

    Thanks so much in advance!

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I didnt even bother with the long code..

    bu does this 'bug' happen wile testing locally or on another server?

    I also wouldnt use loadMovie() anymore.. but use a MovieClipLoader() instance.. gives you more control..and makes things easier to debug/trace

  3. #3
    When testing locally, it doesn't load the XML at all, not even on refresh.

  4. #4

  5. #5
    That's the million dollar question. It seems the first time the AS tries to populate the array mainDataArr from the XML it fails, but when refreshed on a server (I'm guessing because the XML is now in the cache) it succeeds. I'm completely stumped.

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    it could be any number of things.


    1.) if it dont work locally..id start there.. no reason why XML should load when its local in the same folder as the .swf loading it... this should work regardless of being live on a server or not?


    2.) using loadMovie() is old..and not that great/stable.. if you want to have more control over your loading of content.. use a movieClipLoader() instance.. this way you can watch/trace what is loading, where and whats going wrong (if anything)

    3.) loading external.swf can cause lag if ther are needed/required data/compoenets in them.. (again use a movieClipLoader(0 instance to load those too)


    as a last resort.. trying stripping things out until things work.. and trouble shoot one piece at a time.

    the code seems a bit 'weird' to me.... I guess just my style of coding I suppose.

  7. #7
    Like I said it's not my code, so I wouldn't begin to know where to start pulling it apart...

  8. #8
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    start by changing out every loadMovie() call to use a movieClipLoader() instance..


    but before that.. I would concentrate on getting some sort of feedback from loading the XML or find out why its not loading locally when tested on your desktop..

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